题意:设(题目已把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<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<bitset>
#define inc(i,l,r) for(int i=l;i<=r;i++)
#define dec(i,l,r) for(int i=l;i>=r;i--)
#define link(x) for(edge *j=h[x];j;j=j->next)
#define mem(a) memset(a,0,sizeof(a))
#define ll unsigned long long
#define eps 1e-8
#define succ(x) (1LL<<(x))
#define lowbit(x) (x&(-x))
#define sqr(x) ((x)*(x))
#define NM 200015
#define nm 200005
#define pi 3.1415926535897931
using namespace std;
const ll inf=1e9+7;
ll read(){
ll x=0,f=1;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
return f*x;
}
int n,tot,prime[NM],m;
ll _ans,ans;
bool v[NM];
void init(){
m=40000;
inc(i,2,m){
if(!v[i])prime[++tot]=i;
inc(j,1,tot){
if(i*prime[j]>m)break;
v[i*prime[j]]++;
if(i%prime[j]==0)break;
}
}
}
int main(){
init();
int _=read();while(_--){
scanf("%d",&n);_ans=ans=1;
for(int i=1;sqr(prime[i])<=n&&i<=tot;i++)if(n%prime[i]==0){
int t=1;ll s=1,k=1;
while(n%prime[i]==0)n/=prime[i],t++,s*=prime[i],k+=sqr(s);
_ans*=t*s;ans*=k;
}
if(n>1)_ans*=2*n,ans*=1ll*n*n+1;
ans-=_ans;
printf("%llu\n",ans);
}
return 0;
}
Count a * b
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