大家,为什么会超时呀这个

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

adksla @ 2024-01-03 15:48:43

# include<iostream>
# include <cstring>
#include<math.h>
using namespace std;

int zs(int n){
    for(int i=2;i*i<=n;i++){
        if(n%i==0) return 0;
    }
    return 1;
}

int hw(int num){
    int t=num,ans=0;
    while(t){
        ans = ans*10 + t%10;
        t/=10;
    }

    if(num==ans) return 1;
    else return 0;
}

int main()
{   
    int a,b;
    cin >> a >> b;
    for(int i=a;i<=b;i+=2){
        if(zs(i)){
            if(hw(i)){
                cout << i << endl;
            }
        }
    }

    return 0;
 } 

by ChenDibang @ 2024-01-24 17:28:30

@xzh19386551361 感谢大佬


上一页 |