C++求超级素数(Super prime)问题
//该程序简单并可正确运行,希望kutpbpb的回答能对你有所帮助!
#include
using namespace std;
bool isPrimer(int element) //判断是否素数
{
if(element<=1)
return false;
if(element>4)
{
for(int i=2;i<element/2+1;i++)
if(element%i==0)
return false;
}
return true;
}
bool isSuperPrimer(int element) //判断是否超级素数
{
while(isPrimer(element))
{
element/=10;
}
return !element;
}
int main()
{
int count=1;
for(int i=100;i<9999;i++)
if(isSuperPrimer(i))
cout<<"
Find the "<<count++<<"th primer number "<<i<<endl;
return 0;
}
Private Sub Command1_Click()
Dim A As Integer, S As Integer, M As Integer, W As Integer, I As Integer
For A = 100 To 1000
I = Int(Sqr(A))
S = 2
W = 0
Do While S <= I And W = O
If A Mod S = 0 Then
W = 1
Else
S = S + 1
End If
Loop
If W = 0 Then
Print A;
M = M + 1
If M Mod 5 = 0 Then Print
End If
Next A
End Sub
#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");
}
}
还是没读懂题目