题意:设(题目已把f(6)的表给出),
,给定n(n<=1e9),求g(n)
最主要的是求f(m),考虑到模数大于0的情况比较多,所以考虑考虑求ij mod n==0的情况。。
然后其实从题目给的表中看出对一个a来说,他0的个数和gcd(a,n)有关,其实也很容易证明,对一个数a来说,取完gcd部分,其余部分都是多余的,所以只要考虑gcd的部分产生的影响就行,然后就差n/gcd这些因子,即只要b取的是n/gcd的倍数,那么就可以使ab为n的倍数,那么这些b共有n/(n/gcd)=gcd个,所以对每个a,他产生ab余数为0的个数为gcd(a,n),即
然后
为积性函数,可以通过素因子分解求出
设,由于h(n)符合狄利克雷卷积形式,故h(n)也为积性函数
而
因此h(n)也可通过素因子分解求出。。
复杂度为O(Tsqrt(n))
然后又被卡常qaq
分解的时候可以枚举sqrt(n)以内的素因子分解,实测会快10倍左右。。
/**
* ┏┓ ┏┓
* ┏┛┗━━━━━━━┛┗━━━┓
* ┃ ┃
* ┃ ━ ┃
* ┃ > < ┃
* ┃ ┃
* ┃... ⌒ ... ┃
* ┃ ┃
* ┗━┓ ┏━┛
* ┃ ┃ Code is far away from bug with the animal protecting
* ┃ ┃ 神兽保佑,代码无bug
* ┃ ┃
* ┃ ┃
* ┃ ┃
* ┃ ┃
* ┃ ┗━━━┓
* ┃ ┣┓
* ┃ ┏┛
* ┗┓┓┏━┳┓┏┛
* ┃┫┫ ┃┫┫
* ┗┻┛ ┗┻┛
*/
#include
#include
#include
#include
#include
#include
#include
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 1367 Accepted Submission(s): 464
Problem Description
Marry likes to count the number of ways to choose two non-negative integers a and b less than m to make a×b mod m≠0.
Let's denote f(m) as the number of ways to choose two non-negative integers a and b less than m to make a×b mod m≠0.
She has calculated a lot of f(m) for different m, and now she is interested in another function g(n)=∑m|nf(m). For example, g(6)=f(1)+f(2)+f(3)+f(6)=0+1+4+21=26. She needs you to double check the answer.
Give you n. Your task is to find g(n) modulo 264.
Input
The first line contains an integer T indicating the total number of test cases. Each test case is a line with a positive integer n.
1≤T≤20000
1≤n≤109
Output
For each test case, print one integer s, representing g(n) modulo 264.
Sample Input
2 6 514
Sample Output
26 328194
Source
2015ACM/ICPC亚洲区长春站-重现赛(感谢东北师大)
Recommend
hujie | We have carefully selected several similar problems for you: 6447 6446 6445 6444 6443
Statistic | Submit | Discuss | Note