题目:
XXX is puzzled with the question below:
1, 2, 3, ..., n (1<=n<=400000) are placed in a line. There are m (1<=m<=1000) operations of two kinds.
Operation 1: among the x-th number to the y-th number (inclusive), get the sum of the numbers which are co-prime with p( 1 <=p <= 400000).
Operation 2: change the x-th number to c( 1 <=c <= 400000).
For each operation, XXX will spend a lot of time to treat it. So he wants to ask you to help him.
1, 2, 3, ..., n (1<=n<=400000) are placed in a line. There are m (1<=m<=1000) operations of two kinds.
Operation 1: among the x-th number to the y-th number (inclusive), get the sum of the numbers which are co-prime with p( 1 <=p <= 400000).
Operation 2: change the x-th number to c( 1 <=c <= 400000).
For each operation, XXX will spend a lot of time to treat it. So he wants to ask you to help him.
n比较大,m较小
如果能求出快点求出(1 - x内与p互素的所有数的和),这个问题就解决了
设 f(x) = (1 - x内与p互素的所有数的和 )
g(x) = (1 - x内与p不互素的所有数的和 )
sum(x) = (1 - x内与所有数的和 )
f(x) = sum(x) - g(x)
这样变成了怎么求g(x)
g(x)可以用容斥定理做(将x弄成素因子形式,然后算出于各个素因子的倍数的和)
code Link: