题解 | #素数回文#
素数回文
https://www.nowcoder.com/practice/d638855898fb4d22bc0ae9314fed956f
#include <string.h> #include <stdio.h> #define MAX 20 int is_prime(long int num); int main(void) { char str[MAX] = {0}; char ch = 0; long int t = 0; int i = 0, j = 0; while ('\n' != (ch = getchar())) { *(str + i) = ch; i++; } j = strlen(str) - 2; while (j > -1) { *(str + i) = *(str + j); i++; j--; } // 将字符串中的数据转换为格式化数据 sscanf(str, "%ld", &t); printf("%s\n", is_prime(t) ? "prime" : "noprime"); return 0; } int is_prime(long int num) { int flag = 1; for (long int i = 2; (i * i) <= num; i++) { if (num % i == 0) { flag = 0; break; } } return flag; }