题目链接
Nico Number
Time Limit: 2 Seconds Memory Limit: 262144 KB
Kousaka Honoka and
Minami Kotori are playing a game about a secret of
Yazawa Nico.
When the game starts, Kousaka Honoka will
give Minami Kotori an array A of N non-negative
integers. There is a special kind of number in the array, which is called NicoNico-number.
We call a integer x is a NicoNico-number,
if all integers(no more than x) that is coprime with x could
form an Arithmetic Sequence.
Then Minami Kotori will
choose some consecutive part of the array A, wondering the number of NicoNico-number in
this part. What's more, Kousaka Honoka sometimes modify the value of some consecutive elements
in the array. Now it is your task to simulate this game!
Input
There are multiple test cases in input, you should process to the end of file.
For each case, the first line is an integer
N, the number of elements in the array described above. Then second line contains
N integers no greater than 107,
the elements of the array initially.(
1 <= N <= 100,000)
The third line is a integer
T, the number of the operations of the game. Each line of the following
T lines is in one of the following formats.(
1 <= T <= 100,000)
"1 L R" :
Minami Kotori will chooses the consecutive part of the array from the
Lth to
Rth element inclusive. (1 <=
L <= R <= N)
"2 L R v" :
Kousaka Honoka will change the value of the
pth element
A[p] in the array to
A[p]%v for all
L <= p <= R.(
1 <= L <=
R <= N, 1 <= v <= 107)
"3 p x" :
Kousaka Honoka will change the value of the
p th element
A[p] to
x.(
1 <= p <= N, 1 <= x <= 107)
Output
Each time when
Minami Kotori chooses some part of the array, you should output a line, the number of
NicoNico-number in that part.
Sample Input
3
4 6 9
6
1 1 3
1 3 3
2 1 1 10
1 1 3
3 2 4
1 1 3
Sample Output
2
0
2
2
Hint
4 is a
NicoNico-number because only 1 and 3 is coprime with 4 among the integers no greater than 4, and could form an Arithmetic Sequence {1,3}.
题意:
niconico数:所有比x小的数且与x互质的数,从小到大排列是一个等差数列,则x为niconico数。
长度为10^5的数组。三种操作:
第一:询问区间[l,r] niconico数的个数
第二:将区间 [ l , r ] 的数对v取模
第三:将某一个数更新为x
题解:
容易证明:niconico数只有三种:素数,2^k(k>1),6。
那么剩下的难点就是区间取模操作。
可以证明:一个数x,做多取模logx次就变为0。
因此,我们记录区间的最大值,每次区间取模操作的时候判断最大值如果小于v则不用操作,否则暴力更新到底即可。
复杂度O(nlogn)
代码如下:
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include