hdu 4407

题目:
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.

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: http://codepad.org/oGCUGlhb  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值