题解 | #素数回文#
素数回文
https://www.nowcoder.com/practice/d638855898fb4d22bc0ae9314fed956f
#include <stdio.h> int is_suShu(long long int a) {//判断是否时素数 int res = 1; if (a == 1) return 0; //1不是素数,直接返回 // for (long long int i = 2; i < a; i++) { //判断i的平方即可,不用到i<a,否则因为数字太大而超时,参考题解或https://blog.csdn.net/huang_miao_xin/article/details/51331710 for (long long int i = 2; i * i <= a; i++) { if (a % i == 0) return 0; } return res; } long long int huiWenShu(int n) {//把输入的数字变成回文数 long long int res = n; int yuShu;//余数 int a[10]; int index = 0; while (n != 0) { yuShu = n % 10; a[index] = yuShu; index++; n = n / 10; } for (int i = 1; i < index; i++) { res = res * 10 + a[i]; } return res; } int main() { int n; while (scanf("%d", &n) != EOF) { long long int res = huiWenShu(n); if (is_suShu(res) == 1) printf("prime\n"); else printf("noprime\n"); } return 0; }