题解 | #素数回文#

素数回文

https://www.nowcoder.com/practice/d638855898fb4d22bc0ae9314fed956f

#include <errno.h>
#include <math.h>
#include <stdio.h>

long huiwen(int n){
    long out = 0,temp = 0;
    out = n;
    n/=10;
    while (n) {
        out = out*10 + n%10;
        n/=10;
    }
    return out;
}

long is_prime(long n){
    for (long i = 3; i <= sqrt(n); i+=2) {
        if (n%i==0) {
            return 0;;
        }
    }
    return 1;
}
int main() {
    long n;
    while (scanf("%ld", &n) != EOF) { // 注意 while 处理多个 case
        // 64 位输出请用 printf("%lld") to 
        long q = huiwen(n);
        
        int k = is_prime(q);
        if (k==1) {
            printf("prime");
        }else {
            printf("noprime");
        }
    }
    return 0;
}

全部评论

相关推荐

投递拓竹科技等公司10个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务