Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 992 Accepted Submission(s): 336
Goffi wants to know the number of (a,b) satisfy the equality, if n and k are given and 1≤a,b≤n.
Note: gcd(a,b) means greatest common divisor of a and b.
#include <stdio.h> #include <math.h> #include <iostream> #include <algorithm> #include <string.h> #include <vector> using namespace std; typedef long long LL; const LL mod = 1000000007; LL phi(LL x) { LL ans=x; for(LL i=2; i*i<=x; i++) if(x%i==0) { ans=ans/i*(i-1); while(x%i==0) x/=i; } if(x>1) ans=ans/x*(x-1); return ans; } LL n,k; int main() { while(scanf("%lld%lld",&n,&k)!=EOF) { if(n==1) { printf("1\n"); continue; } if(k>1) { if(k==2) printf("1\n"); else printf("0\n"); continue; } LL sum = 0; for(LL i=1; i*i<=n; i++) { if(n%i==0) { if(i*i==n) sum = (sum+phi(i)*phi(i))%mod; else { sum = (sum+2*phi(i)*phi(n/i))%mod; } } } printf("%lld\n",sum); } return 0; }