The doubts about greatest common divisor
Title Description
Xiao Guang is a very like the prime number of people, one day he was learning greatest common divisor when suddenly thought of a problem, he wants to know from 1 to n this n Number of integers (x, Y) of greatest common divisor (x, y), gcd (x, y) = Prime,1<=x,y<=n . But the small aperture just contact greatest common divisor, cannot solve this problem, so he hoped you can help him solve this problem.
Input
Multiple sets of test data for each set of data:
Each behavior an integer N (1<=n<=10^5)
Output
For each group of data:
number of outputs per line (x, y)
Sample input5Sample output5 The direct sieve method is to calculate the prime + Euler function. In the Sieve method to calculate the prime number of the way to each count * (1-1/PI) where Pi is the number of qualitative factors. And then it's a bit of a pit. He said that the number of pairs actually includes the same two number pairs as well as for example (2,4) and (4,2) the order of the different numbers count as two number pairs ... So I just hit a few times without ac ... Post code:
1#include <cstdio>2#include <iostream>3#include <cstring>4 #defineCLR (x) memset (x,0,sizeof (x))5 using namespacestd;6 7 inta[100001];8 intct[100001];9 intpr[100001];Ten voidPrimeintn); One intMain () A { - intn,m,i,j,sum; -Prime100000); the while(SCANF ("%d", &n) = =1) - { -sum=0; - for(i=1;p r[i]<=n;i++) + { -j=n/Pr[i]; +sum+=Ct[j]; A } atprintf"%d\n", sum*2+i-1); - } - - } - voidPrimeintN) - { in CLR (a); - CLR (PR); to intnum=0; +a[0]=a[1]=1; - for(intI=1; i<=n;i++) thect[i]=i; *ct[1]=0; $ for(intI=1; i<=n;i++)Panax Notoginseng if(!A[i]) - { the for(intj=i;j<=n;j+=i) + { Aa[j]=1; thect[j]=ct[j]/i* (I-1); + } -pr[++num]=i; $ } $ for(intI=1; i<=n;i++) -ct[i]+=ct[i-1]; -pr[0]=num; the return ; -}
A simple geometric transformation topic description
Little Light recently in the study of geometric transformation, the teacher left him a job, on the two-dimensional plane has n points (x, y), the teacher gave m geometric transformation to N Point, requiring a small light output to transform the coordinates of n points (x', y '). Xiao Guang in order to lazy, ask you to help him write a program to complete the teacher's homework.
As the light has just learned geometric transformation, the teacher will only give four kinds of transformations, as follows:
Translation Transformation: (x', y ') = (x+p,y ' +q) the input format of the program is:1 P q (p,q is an integer )
Scale transform: (x', y ') = (x*l,y*l) the input format of the program is:2 L (L is an integer )
Upside Down: (x', y ') = (x,-y) the input format of the program is:3
Flip around: (x', y ') = (-x,y) the input format of the program is:4
Input
Multiple sets of test data for each set of data:
First act N (1<=n<=10^5)
Then the following n lines,n dots (x, y) where x, y are integers
Then the line is M (1<=m<=10^5)
Then the following M-line,m - transform, input format as described above.
Output
For each group of data:
Outputs n rows, and each behavior transforms point coordinates.
Sample input2 1 1 2 2 1 1 1 1Sample output2 2 3 3 There is nothing to say about this question. In fact, is not the number theory, but the top of the transformation of the name of the head = =. And then, a look at the amount of data if a single processing must be timed out. So I thought of all the processing into one treatment. and then, using CT to represent all the processing after the reversal of the transformation =1 is not flipped, =-1 for flipping. Two flips is equivalent to not flipping. CT=-CT after each flip. use L to indicate the zoom factor after all processing. then the translation transformation and the flip and the scaling correlation, the processing is troublesome, uses the acum to save the last processing to finish the translation how much. Each translation transformation is acum=+a*ct. The size of each scaling transform is acum=*t,t each time you zoomFor each number a[i] after processing for a[i].x=a[i].x*l*ctx+acumx*ctx;
a[i].y=a[i].y*l*cty+acumy*cty;The code is handled as follows:
1#include <cstdio>2#include <iostream>3 using namespacestd;4 structpos{5 intx, y;6}a[100001];7 intMain ()8 {9 intCtx,cty,acumx,acumy;Ten intn,m,k,l,t,p,q; One while(SCANF ("%d", &n) = =1) A { - for(intI=1; i<=n;i++) -scanf"%d%d",&a[i].x,&a[i].y); thescanf"%d",&m); -Ctx=cty=l=1; -acumx=acumy=0; - for(intI=1; i<=m;i++) + { -scanf"%d",&k); + if(k==1) A { atscanf"%d%d",&p,&q); -acumx+=ctx*p; -acumy+=cty*Q; - } - if(k==2) - { inscanf"%d",&t); -l*=T; toacumx*=T; +acumy*=T; - } the if(k==3) *cty=-Cty; $ if(k==4)Panax Notoginsengctx=-CTX; - } the for(intI=1; i<=n;i++) + { Aa[i].x=a[i].x*l*ctx+acumx*CTX; thea[i].y=a[i].y*l*cty+acumy*Cty; +printf"%d%d\n", a[i].x,a[i].y); - } $ } $ return 0; -}
View Code
14 The number of games in Anhui, etc.