题解 | #素数回文#
素数回文
https://www.nowcoder.com/practice/d638855898fb4d22bc0ae9314fed956f
#include <stdio.h> #include <math.h> int main() { int n; while (scanf("%d", &n) != EOF) { // 注意 while 处理多个 case // 64 位输出请用 printf("%lld") to int i=0; int x=0; long long num=0;//储存回文数 int digit=0; x=n;//代替n进行计算 while(x) { x/=10; digit++;//得到数位 } x=n; num=n*pow(10,--digit); while(x) { if(x!=n) { num+=x%10*pow(10,--digit); } x/=10; } //判断素数 for(i=2;i<=pow(num,1.0/2);i++) { if(num%i==0) { break; } } if(i>pow(num,1.0/2)) { printf("prime\n"); } else { printf("noprime\n"); } } return 0; }