暴力求解,从1开始,求出每个数位数的和,再依次判断是否为质数,如果不是质数直接跳过,否则记录下个数,直到和n相等退出循环输出即可
PaiGuDragon is an excellent number theory player.
For a positive interger number xxx, if the digit sum of xxx is a prime number, the PaiGuDragon calls xxx nice number.(i.e. digit sum of 269 equals to 17, and 17 is a prime number so 269 is nice!)
PaiGuDragon is curious about what is the nnn th smallest nice number.
#include<bits/stdc++.h>
using namespace std;
int zhishu(int x){
int i;
if (1 == x)
{
return 0;
}
for (i = 2; i <= sqrt(x); ++i) {
if(x%i==0){
return 0;
}
}
return 1;
}
int he(int n){
int sum=0;
while(n){
sum+=n%10;
n/=10;
}
return sum;
}
int main(){
int n,cnt=0,i=2;
cin>>n;
for(i=2;cnt<n;i++){
if(zhishu(he(i))==1){
cnt++;
}
}
cout<<i-1;
return 0;
}