Problem Description
Marry likes to count the number of ways to choose two non-negative integers a and b less than m to make
mod
.
Let’s denote as the number of ways to choose two non-negative integers a and b less than m to make mod .
She has calculated a lot of f(m) for different m, and now she is interested in another function
. For example,
. She needs you to double check the answer.
Give you
. Your task is to find
) modulo
.
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.
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亚洲区长春站-重现赛(感谢东北师大)
先推一下
:
可以发现 已经是互质了,所以要整除m, 必须是 的倍数,其数量显然是 个,则:
这里是老套路,去枚举gcd:最终就有:
来看 ,所以:
把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;
}