摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1431View Code 1 #include<stdio.h> 2 #include<string.h> 3 bool prime[10000002];//int一直超内存,wa好多次,改成bool就过了 4 int pos[664580]; 5 int num; 6 void puan_prim() 7 { 8 memset(pos,-1,sizeof(pos)); 9 num=0;10 memset(prime,false,sizeof(prime));11 for(...
阅读全文
摘要:http://acm.nyist.net/JudgeOnline/problem.php?pid=330View Code 1 #include<stdio.h> 2 #include<string.h> 3 int vis[1000005]; 4 int main() 5 { 6 int t; 7 int n; 8 scanf("%d",&t); 9 while(t--)10 {11 memset(vis,0,sizeof(vis));12 scanf("%d",&n);13 if(n==1)14 ...
阅读全文
摘要:http://acm.nyist.net/JudgeOnline/problem.php?pid=205View Code 1 #include<stdio.h> 2 #include<string.h> 3 int main() 4 { 5 long long t; 6 int len; 7 char str[1000010]; 8 scanf("%lld",&t); 9 while(t--)10 {11 long long yushu=0;12 scanf("%s",str);13 len...
阅读全文
摘要:http://acm.nyist.net/JudgeOnline/problem.php?pid=139View Code 1 #include<stdio.h> 2 #include<string.h> 3 int jiecheng(int x) 4 { 5 int jie=1; 6 for(int i=2;i<=x;i++) 7 jie*=i; 8 return jie; 9 }10 int main()11 {12 int t;13 int len;14 char ch;15 char str[13];16 sca...
阅读全文
摘要:http://acm.nyist.net/JudgeOnline/problem.php?pid=102View Code 1 #include<stdio.h> 2 int main() 3 { 4 long long a,b,n; 5 int t; 6 scanf("%d",&t); 7 while(t--) 8 { 9 long long t=1;10 scanf("%lld%lld%lld",&a,&b,&n);11 for(;b;b>>=1,a=a*a%n)12 {13 ...
阅读全文
摘要:http://www.reait.com/1/post/2012/03/quickly-take-mode.html
阅读全文
摘要:View Code 1 #include<stdio.h> 2 #include<string.h> 3 int prime[2000010]; 4 void puan_prime() 5 { 6 7 for(int i=2;i<=2000010;i++) 8 { 9 if(!prime[i])10 {11 for(int j=i+i;j<=2000010;j+=i)12 prime[j]=1;13 }14 }15 }16 int main()17 {18 ...
阅读全文
摘要:http://acm.nyist.net/JudgeOnline/problem.php?pid=451View Code 1 #include<stdio.h> 2 long long a[22],b[22]; 3 void cuo_pai() 4 { 5 a[1]=0; 6 a[2]=1; 7 for(int i=3;i<=22;i++) 8 a[i]=(i-1)*(a[i-1]+a[i-2]); 9 }10 int main()11 {12 long long aa,b;13 cuo_pai();14 while(~scanf(...
阅读全文
摘要:View Code 1 #include<stdio.h> 2 #include<string.h> 3 int a[1000010]; 4 void prime() 5 { 6 7 int num=0; 8 for(int i=2;i<=1000010;i++) 9 {10 if(!a[i])11 {12 num++;13 for(int j=1;j*i<=1000010;j++)14 a[...
阅读全文
摘要:http://acm.nyist.net/JudgeOnline/problem.php?pid=69View Code 1 #include<stdio.h> 2 #include<math.h> 3 int main() 4 { 5 int t; 6 int n; 7 double sum; 8 scanf("%d",&t); 9 while(t--)10 {11 sum=0;12 scanf("%d",&n);13 for(int i=n;i>=1;i--)14 sum+=l...
阅读全文
摘要:void init_prim() { memset(visit, true, sizeof(visit)); int num = 0; for (int i = 2; i <= n; ++i) { if (visit[i] == true) { num++; prime[num] = i; } for (int j = 1; ((j <= num) && (i * prime[j] <= n)); ++j) {...
阅读全文
摘要:View Code 1 #include<stdio.h> 2 int gcd(int x,int y) 3 { 4 int r; 5 while(y!=0) 6 { 7 r=x%y; 8 x=y; 9 y=r;10 }11 return x;12 }13 int main()14 {15 int a,b;16 while(~scanf("%d%d",&a,&b))17 {18 printf("%d\n",gcd(a,b));19 }20 }
阅读全文
摘要:View Code 1 #include<stdio.h> 2 int Eular(int n) 3 { 4 int i; 5 int ans=n; 6 for(i=2;i*i<=n;++i) 7 { 8 if(n%i==0) //如果i和n不互质,i的倍数全都与n不互质 9 {10 ans-=ans/i; //排除掉i的倍数11 while(n%i==0)12 n=n/i; //去掉n中含有的所有i因子13 ...
阅读全文