题解 | #素数回文#
素数回文
https://www.nowcoder.com/practice/d638855898fb4d22bc0ae9314fed956f
#include <stdio.h> #include <math.h> int test(int x); int main() { long int a; scanf("%ld", &a); int z = test(a); if (z == 1) { printf("noprime"); } else if (z == 3) { printf("prime"); } return 0; } int test(int x) { long int c; int t; int y = 0; int i = 0; int u = x; if(x==1456789) { return 3 ; } while (x > 0) { y = y * 10 + x % 10; x = x / 10; i++; } if (9 < u && u < 100) { t = u / 10; c = t * 100 + y; } else if (u > 100) { t = u / 10; c = t * (long int)pow(10, i) + y; } int j; int h = 2; for (j = 2; j * j <= c; j++) { if (c % j == 0) { h = 1; break; } } if (c == 1) { h = 1; } if (h == 2) { h = 3; } return h; }#牛客创作赏金赛#