『算法-ACM竞赛-数学-数论』HDU 5382 GCD?LCM?(详细推导,不懂打我)
『算法-ACM 竞赛-数学-数论』HDU 5382 GCD?LCM?(详细推导,不懂打我)
Describtion
First we define:
(1) lcm(a,b), the least common multiple of two integers a and b, is the smallest positive integer that is divisible by both a and b. for example, lcm(2,3)=6 and lcm(4,6)=12.
(2) gcd(a,b), the greatest common divisor of two integers a and b, is the largest positive integer that divides both a and b without a remainder, gcd(2,3)=1 and gcd(4,6)=2.
(3) [exp], exp is a logical expression, if the result of exp is true, then [exp]=1, else [exp]=0. for example, [1+2≥3]=1 and [1+2≥4]=0.
Now Stilwell wants to calculate such a problem:
F(n)=∑i=1n∑j=1n [ lcm(i,j)+gcd(i,j)≥n ]S(n)=∑i=1nF(i)
Find S(n) mod 258280327.
Input
The first line of the input contains a single number T, the number of test cases.
Next T lines, each line contains a positive integer n.
T≤105, n≤106.
Output
T lines, find S(n) mod 258280327.
Sample Input
8
1
2
3
4
10
100
233
11037
Sample Output
1
5
13
26
289
296582
3928449
213582482
推导详细
强烈建议:不赞成网上像我前面的因素和求 Q(N),这里的先求因子个数再用快速幂求解,但是这里的不同因子个数恰好可以用线性筛求解,但是在其余题目中不一定恰好可以使用,应该使用积性函数的性质直接使用线性筛,这样时间复杂度上少了一个快速幂。
好久没用 scanf, printf 超时,然后写上了,忘了换行,题解叫上过来,我的就一直 wa,写了对拍也是对的,我都懵了,感叹造化弄人的时候,一点一点用标程替换,知道吧 printf 换掉我就明白了,我太难了,凌晨 1.30 了,还满怀兴奋。睡不着。
1 |
|