Little D is a math enthusiast, and he's obsessed with numbers to the point of madness.
We use D = gcd (A, B) to denote the greatest common divisor of a, B, and small d that this intimate relationship can be described by both parents, at which point we call the number of pairs (a, b) of the parents of D.
Unlike normal parents, he has too many parents for the same d >_<
For example: (4, 6), (6, 4), (2, 100) are both parents of 2.
So the question is, for 0 < a <= A, 0 < b <= B, how many ordered pairs (A, b) are the parents of d?
Test instructions is the number of points to satisfy the 0<X<=N,0<Y<=M,GCD (x, y) =d;
Set F[i] for gcd (x, y) =i of the number of points, according to the multiplication principle can be satisfied i|gcd (x, y) of the number of point pairs (n/i) * (m/i), we only need to reduce the number of the following sum (F[d*i]), D>=2,d*i<=min (n,m);
This is a recursive forward from the back, the time complexity is O (NLOGN);
#include <iostream>#include<cstdio>#include<cstring>#include<string>#include<cstdlib>#include<ctime>#include<vector>#include<algorithm>#include<queue>#include<map>using namespacestd;#defineLL Long Longintn,m,d; LL f[1010000];voidinit () {scanf ("%d%d%d",&n,&m,&d); LL sum=0; if(n>m) swap (N,M); for(inti=n/d*d;i;i-=d) {F[i]= (ll) n/i) * ((LL) m/i); for(intj=i<<1; j<=n;j+=i) f[i]-=F[j]; } cout<<f[d]<<Endl; }intMain () {Freopen ("1.in","R", stdin); Freopen ("1.out","W", stdout); Init (); return 0;}
Parental number tolerance