2820:yy gcd time limit:10 Sec Memory limit:512 MB
submit:1624 solved:853
[Submit] [Status] [Discuss] Description God Ben yy after abusing the number theory to give silly xkac out a question given N, M, 1<=x<=n, 1<=y<=m and gcd (x, y) for prime numbers (x, y) How many to KAC this silly x must not, so to you to consult ... Multiple input inputs the first line an integer t to represent the number of data groups next T line, two positive integers per line, representing N, moutputt rows, one integer per line representing the result of Group I data sample Input2
10 10
100 100
Sample Output30
2791
HINT
T = 10000
N, M <= 10000000
And bzoj2705 are like http://www.cnblogs.com/candy99/p/6200745.html.
However, unlike N and M, direct Euler functions cannot be used
Reference: http://blog.csdn.net/acdreamers/article/details/8542292 && POPOQQQ Courseware
The same function as the previous question:
The logarithm that is satisfied and
The logarithm that is satisfied and
Obviously, after the inversion gets
Can enumerate each prime number, apply the practice of the previous question, p is equivalent to K,d*p is a multiple of p ... It's like the last question in my WT1.
Actually d just enumerate to min (n,m)/P
However, the complexity can not withstand, about N/LOGN*SQRT (n)
We set, then continue to get
Why did you do it? Since then it is found that the F function has nothing to do with P and D (otherwise enumerations P and D are also enumerated T)
can refer to the front, the rest of the piece can handle the prefix and do O (1), the front and then divide the block, do O (sqrt (n))
Wt:
How to find G (T) =σ{p| T && IsPrime (P)}miu (t/p)
Act 1.
You just need to enumerate every prime force.
Because of the conclusion of 1/1+1/2+1/3+...+1/n=o (LOGN), each prime number is enumerated when it is averaging O (LOGN).
And prime numbers happen to have O (N/logn), so the brute force enumeration is O (n).
Act 2.
Linear sieve
#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>using namespaceStd;typedefLong Longll;Const intn=1e7+5; inlineintRead () {CharC=getchar ();intx=0, f=1; while(c<'0'|| C>'9'){if(c=='-') f=-1; C=GetChar ();} while(c>='0'&&c<='9') {x=x*Ten+c-'0'; C=GetChar ();} returnx*F;}intn,m;BOOLNotp[n];intP[n],mu[n],g[n];voidsieve () {mu[1]=1; for(intI=2; i<n;i++){ if(!notp[i]) p[++p[0]]=i,mu[i]=-1; for(intj=1; j<=p[0]&&i*p[j]<n;j++) {Notp[i*p[j]]=1; if(i%p[j]==0) {Mu[i*p[j]]=0; Break; } mu[i*p[j]]=-Mu[i]; } } for(intj=1; j<=p[0];j++) for(inti=p[j];i<n;i+=P[j]) g[i]+=mu[i/P[j]]; for(intI=1; i<n;i++) g[i]+=g[i-1];} ll Cal (intNintm) { if(n>m) swap (N,M); ll ans=0;intR; for(intI=1; i<=n;i=r+1) {R=min (n/(n/i), m/(m/i)); Ans+ = (ll) (g[r]-g[i-1]) * (n/i) * (m/i); } returnans;}intMainintargcConst Char*argv[]) {sieve (); intt=read (); while(t--) {n=read (); m=read (); printf ("%lld\n", Cal (N,m)); } return 0;}
Bzoj 2820:yy's GCD [MO] "study notes"