Bzoj2820:yy's GCD

Source: Internet
Author: User

Exercises

In the face of such a question, Konjac Konjac had to carry the problem ...

Kneeling iwtwiioi!!!

Http://www.cnblogs.com/iwtwiioi/p/4132095.html

Code:

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>Ten#include <queue> One#include <string> A #defineINF 1000000000 - #defineMAXN 10000000+5 - #defineMAXM 100000+5 the #defineEPS 1e-10 - #definell Long Long - #definePA pair<int,int> - #defineFor0 (i,n) for (int i=0;i<= (n); i++) + #defineFor1 (i,n) for (int i=1;i<= (n); i++) - #defineFor2 (i,x,y) for (int i= (x); i<= (y); i++) + #defineFor3 (i,x,y) for (int i= (x); i>= (y); i--) A #defineFor4 (i,x) for (int i=head[x],y=e[i].go;i;i=e[i].next,y=e[i].go) at #defineMoD 1000000007 - using namespacestd; -InlineintRead () - { -     intx=0, f=1;CharCh=GetChar (); -      while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} in      while(ch>='0'&&ch<='9') {x=Ten*x+ch-'0'; ch=GetChar ();} -     returnx*F; to } + intTOT,P[MAXN],MU[MAXN]; - ll G[MAXN]; the BOOLV[MAXN]; * void Get() $ {Panax Notoginsengmu[1]=1; -For2 (I,2,10000000) the     { +         if(!v[i]) p[++tot]=i,mu[i]=-1, g[i]=1; A For1 (J,tot) the         { +             intk=i*P[j]; -             if(k>10000000) Break; $v[k]=1; $             if(I%p[j]) mu[k]=-mu[i],g[k]=mu[i]-G[i]; -             Else{mu[k]=0; g[k]=mu[i]; Break;} -         } the     } -For1 (I,10000000) g[i]+=g[i-1];Wuyi } the intMain () - { WuFreopen ("Input.txt","R", stdin); -Freopen ("output.txt","W", stdout); About     Get(); $     intt=read (); -      while(t--) -     { -ll N=read (), M=read (), ans=0; A         if(n>m) swap (n,m); +          for(intI=1, pos;i<=n;i=pos+1) the         { -Pos=min (n/(n/i), m/(m/i)); $ans+= (g[pos]-g[i-1]) * (n/i) * (m/i); the         } theprintf"%lld\n", ans); the     }         the     return 0; -}
View Code 2820:yy gcd time limit:10 Sec Memory limit:512 MB
submit:782 solved:391
[Submit] [Status] 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

Bzoj2820:yy's GCD

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.