题解:
面对这么神的题,蒟蒻只好搬运题解。。。
跪烂iwtwiioi!!!
代码:
1 #include<cstdio> 2 #include<cstdlib> 3 #include<cmath> 4 #include<cstring> 5 #include<algorithm> 6 #include<iostream> 7 #include<vector> 8 #include<map> 9 #include<set> 10 #include<queue> 11 #include<string> 12 #define inf 1000000000 13 #define maxn 10000000+5 14 #define maxm 100000+5 15 #define eps 1e-10 16 #define ll long long 17 #define pa pair<int,int> 18 #define for0(i,n) for(int i=0;i<=(n);i++) 19 #define for1(i,n) for(int i=1;i<=(n);i++) 20 #define for2(i,x,y) for(int i=(x);i<=(y);i++) 21 #define for3(i,x,y) for(int i=(x);i>=(y);i--) 22 #define for4(i,x) for(int i=head[x],y=e[i].go;i;i=e[i].next,y=e[i].go) 23 #define mod 1000000007 24 using namespace std; 25 inline int read() 26 { 27 int x=0,f=1;char ch=getchar(); 28 while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} 29 while(ch>='0'&&ch<='9'){x=10*x+ch-'0';ch=getchar();} 30 return x*f; 31 } 32 int tot,p[maxn],mu[maxn]; 33 ll g[maxn]; 34 bool v[maxn]; 35 void get() 36 { 37 mu[1]=1; 38 for2(i,2,10000000) 39 { 40 if(!v[i])p[++tot]=i,mu[i]=-1,g[i]=1; 41 for1(j,tot) 42 { 43 int k=i*p[j]; 44 if(k>10000000)break; 45 v[k]=1; 46 if(i%p[j])mu[k]=-mu[i],g[k]=mu[i]-g[i]; 47 else {mu[k]=0;g[k]=mu[i];break;} 48 } 49 } 50 for1(i,10000000)g[i]+=g[i-1]; 51 } 52 int main() 53 { 54 freopen("input.txt","r",stdin); 55 freopen("output.txt","w",stdout); 56 get(); 57 int T=read(); 58 while(T--) 59 { 60 ll n=read(),m=read(),ans=0; 61 if(n>m)swap(n,m); 62 for(int i=1,pos;i<=n;i=pos+1) 63 { 64 pos=min(n/(n/i),m/(m/i)); 65 ans+=(g[pos]-g[i-1])*(n/i)*(m/i); 66 } 67 printf("%lld\n",ans); 68 } 69 return 0; 70 }
2820: YY的GCD
Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 782 Solved: 391
[Submit][Status]
Description
Input
Output
Sample Input
10 10
100 100
Sample Output
2791
HINT
T = 10000
N, M <= 10000000