C++求超级素数(Super prime)问题
发布网友
发布时间:2022-10-05 15:28
我来回答
共2个回答
热心网友
时间:2023-10-19 12:18
//#include "stdafx.h"//vc++6.0加上这一行.
#include "stdio.h"
bool prime(int n){
int i;
if(n>2 && !(n&1) || n<2)return false;
for(i=3; i*i<=n;i+=2)
if(!(n%i)) return false;
return true;
}
void main(void){
int a[]={1,11,101,1001,10001,100001,1000001,10000001,100000001},T,k,i,n,s,f;
printf("How many test?\nT=");
scanf("%d",&T);
while(f=0,T--){
printf("How many digits is this(k<10)?...\nk=");
while(1){
scanf("%d",&k);
if(k>0 && k<10) break;
printf("Error,input k again...\nk=");
}
if(k>1)
for(i=a[k-1],n=(i-1)*10;i<n;i+=2){
for(s=a[k-1]-1;s;s/=10)
if(!prime(i/s)) break;
if(s==0) printf("%d\n",f=i);
}
else printf("2\n3\n5\n7\n");
if(f==0) printf("No such number...\n");
}
}
热心网友
时间:2023-10-19 12:18
还是没读懂题目