打表规律猜想代码:
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
#include<stdio.h> #include<string.h> const int N=100; int a[N]; bool p[N]; int main() { memset(p,true,sizeof(p)); for(int i=0;i<N;i++) a[i]=i; for(int j=2;j<N;j++) { if(p[j]) { for(int k=2;j*k<N;k++) if(p[j*k])p[j*k]=false; else p[j*k]=true; } for(int i=2;i<N;i++) if(p[i])printf("%d ",a[i]); else printf(" "); printf("\n"); } return 0; }
#include <stdio.h> #include <string.h> #include <math.h> #define MAX 65536 bool div(char *p,int n) { char temp[1000]; int i,sum=0,len=0; for(i=0; p[i]!=0; i++) { sum=sum*10+p[i]-'0'; temp[len++]=sum/n+'0'; sum%=n; } temp[len]=0; if(sum==0) { for(i=0; temp[i]=='0'; i++); strcpy(p,temp+i); return 1; } else return 0; } int main() { bool num[MAX+1]; int prime[MAX],len=0,i,j; double t=sqrt(MAX); memset(num,1,sizeof(num)); for(i=2; i<t; i++) { if(num[i]) { for(j=2; i*j<=MAX; j++)num[i*j]=0; } } for(i=2; i<=MAX; i++) { if(num[i])prime[len++]=i; } char str[1000]; while(scanf("%s",str),strcmp(str,"0")!=0) { if(strcmp(str,"1")==0) { printf("no\n"); continue; } int count; for(i=0; i<len; i++) { count=0; while(div(str,prime[i])) { count++; if(count>=2)break; } if(count>=2)break; } if(count>=2)printf("no\n"); else printf("yes\n"); } return 0; }