题目:用 0,1,2,3 \cdots 70,1,2,3⋯7 这 88 个数组成的所有整数中,质数有多少个(每个数字必须用到且只能用一次)。
提示:以 00 开始的数字是非法数字。
#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <cstring>
#include <cmath>
#include <stdio.h>
using namespace std;
int main()
{
int sum=0;
char str[105]={"01234567"};
do
{
if(str[0]!='0')
{
int i;
int n=atoi(str);//字符串转化为整型
double m=sqrt(n);
for(i=2;i<=m;i++)
{
if(n%i==0)
{
break;
}
}
if(i>m)
{
sum++;
}
}
}while(next_permutation(str,str+strlen(str)));
cout<<sum<<endl;
return 0;
}