Reflect
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 288 Accepted Submission(s): 174
Problem Description
We send a light from one point on a mirror material circle,it reflects
N
times and return the original point firstly.Your task is calcuate the number of schemes.
Input
First line contains a single integer
T
which denotes the number of test cases.
For each test case, there is an positive integer N.
For each test case, there is an positive integer N.
Output
For each case, output the answer.
Sample Input
14
Sample Output
4
白痴互质求法:
#pragma comment(linker, "/STACK:1024000000,1024000000") #include <iostream> #include <stdio.h> #include <math.h> #include <string> #include <queue> #include <string.h> #include <map> #include <set> #include <vector> #include <algorithm> #include <stdlib.h> using namespace std; #define eps 1e-8 #define INF 20000000005 #define rd(x) scanf("%d",&x) #define rdLL(x) scanf("%I64d",&x) #define rd2(x,y) scanf("%d%d",&x,&y) #define ll long long #define mod 998244353 #define maxn 100005 #define maxm 1000 #define minn 0.00000001; bool judge(int a,int b){ int temp=0; while(b!=0){ temp=b; b=a%b; a=temp; } if(a==1) return 1;//如果最大公约数是1,那么两数互质 else return 0; } int main() { int Case,n; rd(Case); while(Case--){ rd(n); int coun = 1; for(int i=2 ; i<n+1 ; i++) if( judge(i,n+1) ) coun++; printf("%d ",coun); } return 0; }
欧拉函数:(两种方式)
#pragma comment(linker, "/STACK:1024000000,1024000000") #include <iostream> #include <stdio.h> #include <math.h> #include <string> #include <queue> #include <string.h> #include <map> #include <set> #include <vector> #include <algorithm> #include <stdlib.h> using namespace std; #define eps 1e-8 #define INF 20000000005 #define rd(x) scanf("%d",&x) #define rdLL(x) scanf("%I64d",&x) #define rd2(x,y) scanf("%d%d",&x,&y) #define ll long long #define mod 998244353 #define MAX 1000005 #define maxm 1000 #define minn 0.00000001; ///但个数的的欧拉函数 //long long eular(long long n){ // long long ans = n; // for(int i=2 ; i*i <= n ; i++){ // if(n%i == 0){ // ans = ans - ans/i; ///欧拉函数 // while(n%i == 0) // n = n/i; // } // } // if( n>1 ) ans=ans-ans/n; // return ans; //} ///筛法欧拉函数(打表) int eular [MAX]; void getEular(){ memset(eular,0,sizeof(eular)); eular[1] = 1; for(int i=2;i<=MAX;i++){ if(!eular[i]) for(int j=i;j<=MAX ; j += i){ if(!eular[j]) eular[j] = j; eular[j] = eular[j]/i*(i-1); } } } int main() { int Case,n; getEular(); rd(Case); while(Case--){ rd(n); printf("%d ",eular[n+1]); //printf("%lld ",eular(n+1)); } return 0; }