最后一个超时

P1217 [USACO1.5] 回文质数 Prime Palindromes

vckk @ 2023-12-18 21:32:33

#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<string.h>
int ss(long n){
    if(n==1){
        return -1;
    }else{
        for(long i=2;i<=sqrt(n);i++){
            if(n%i==0){
                return -1;
            }
        }
        return 1;
    }
}
int main(){
    long a,b,i,j,q;
    char s[20];
    int count=1;
    scanf("%ld%ld",&a,&b);
    for(i=a;i<=b;i++){  
        count=1;
        if(i%2!=0){
        sprintf(s,"%ld",i);
            for(j=0;j<strlen(s)/2;j++){
                if(s[j]!=s[strlen(s)-1-j]){
                    count=0;
                    break;
                }
            }
            if(count==1){
                if(ss(i)==1){
                    printf("%ld\n",i);

            }
        }
    }
}
    return 0;
}

by __qkj__ @ 2023-12-18 21:35:29

@vckk418 开O2


by vckk @ 2023-12-18 21:53:09

@hh6qkj 什么意思?


by vckk @ 2023-12-18 21:56:56

@hh6qkj 效率更高的判断质数方法??


|