暴力计算,注意最高位不能为0
#include<bits/stdc++.h>
using namespace std;
bool prime(int n)
{
if(n==0||n==1)
return 0;
if(n==2) return 1;
for(int i=2;i*i<n;i++){
if(n%i==0)
return 0;
}
return 1;
}
int main()
{
int a,sum=0;
for(int i1 = 1;i1<8;i1++){
for(int i2 = 0;i2<8;i2++){
for(int i3 = 0;i3<8;i3++){
for(int i4 = 0;i4<8;i4++){
for(int i5 = 0;i5<8;i5++){
for(int i6 = 0;i6<8;i6++){
for(int i7 = 0;i7<8;i7++){
for(int i8 = 0;i8<8;i8++){
a = i1*10000000+i2*1000000+i3*100000+i4*10000+i5*1000+i6*100+i7*10+i8;
if((i1!=i2)&&(i1!=i3)&&(i1!=i4)&&(i1!=i5)&&(i1!=i6)&&(i1!=i7)&&(i1!=i8)
&&(i2!=i3)&&(i2!=i4)&&(i2!=i5)&&(i2!=i6)&&(i2!=i7)&&(i2!=i8)
&&(i3!=i4)&&(i3!=i5)&&(i3!=i6)&&(i3!=i7)&&(i3!=i8)
&&(i4!=i5)&&(i4!=i6)&&(i4!=i7)&&(i4!=i8)
&&(i5!=i6)&&(i5!=i7)&&(i5!=i8)
&&(i6!=i7)&&(i6!=i8)
&&(i7!=i8)&&prime(a))
sum++;
}
}
}
}
}
}
}
}
cout<<sum<<endl;
return 0;
}