复习stl
next_permutation
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
bool prime(int x)
{
if(x<2)
return false;
for(int i = 2;i*i<=x;i++) //素数判定
if(x%i == 0)
return false;
return true;
}
int main()
{
int ans=0,tf,tmp;
int a[8]={0,1,2,3,4,5,6,7};
do
{
tf=0;
tmp=0;
for(int i=7;i>=0;i--)
{
tmp+=a[i]*pow(10,tf); //十进制串转int
tf++;
}
if(tmp>=10000000&&prime(tmp)) //0开头无效 需要舍弃
ans++;
}
while(next_permutation(a,a+8)); //从升序数组排列至全降序
cout<<ans<<endl;
return 0;
}