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
a
×
b
mod
m≠0
m
≠
0
.
Let’s denote f(m) f ( m ) as the number of ways to choose two non-negative integers a and b less than m to make a×b a × b mod m≠0 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)
g
(
n
)
=
∑
m
|
n
f
(
m
)
. For example,
g(6)=f(1)+f(2)+f(3)+f(6)=0+1+4+21=26
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
n
. Your task is to find ) modulo
264
2
64
.
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
≤
T
≤
20000
1≤n≤109
1
≤
n
≤
10
9
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亚洲区长春站-重现赛(感谢东北师大)
先推一下
f
f
:
可以发现 m(m,i)和i(m,i) m ( m , i ) 和 i ( m , i ) 已经是互质了,所以要整除m, j j 必须是的倍数,其数量显然是 (m,i) ( m , i ) 个,则:
这里是老套路,去枚举gcd:最终就有:
来看 g g ,所以:
把d拿到最外层:
到这里就是去枚举n的所以因子了,用唯一分解来做,然后搜索枚举因子即可。
代码:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#define ull unsigned long long
#define ll long long
#define ul unsigned int
#define maxn 40000
using namespace std;
bool isP[maxn];
int prime[maxn];
int cnt;
void init()
{
for(int i=2;i<maxn;i++)
{
if(!isP[i])prime[cnt++]=i;
for(int j=0;j<cnt&&i*prime[j]<maxn;j++)
{
isP[i*prime[j]]=true;
if(i%prime[j]==0)break;
}
}
}
int fac[50];
int e[50];
int k;
void getFac(int x)
{
k=0;
for(int i=0;prime[i]*prime[i]<=x;i++)
{
if(x%prime[i]==0)
{
fac[k]=prime[i];
e[k]=0;
while(x%prime[i]==0)
{
x/=prime[i];
++e[k];
}
++k;
}
}
if(x>1){fac[k]=x;e[k++]=1;}
}
ull ans=0;
void dfs(int cur,ull temp)
{
if(cur==k)
{
ans+=temp*temp;
return;
}
dfs(cur+1,temp);
ull now=temp;
for(int i=1;i<=e[cur];i++)
{
now*=fac[cur];
dfs(cur+1,now);
}
}
ull mod=0;
int main()
{
mod=~mod;
init();
int t;
cin>>t;
int n;
while(t--)
{
scanf("%d",&n);
int total=1;
getFac(n);
ans=0;
dfs(0,1);
for(int i=0;i<k;i++)total*=e[i]+1;
ull _n=n;
_n*=total;
_n=mod-_n+1;
cout<<ans+_n<<endl;
}
return 0;
}