33TLE好多

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

michaelwanghaoyu @ 2024-11-13 12:35:12

救命

#include<bits/stdc++.h>
using namespace std;
bool ss(int i)
{
    bool iss=1;
    for (int ni=2;ni<i;ni++)
    {
        if (i%ni==0)
        {
            iss=0;
        }
    }
    if (iss) 
    {
        return true;
    } 
    else
    {
        return false;
    }
}
int main()
{
    long long c,b;
    cin>>c>>b;
    for (long long a=c;a<=b;a++)
    {
        long long ts=a;
        long long ls=0;
        while (ts)
        {
            ls=ls*10+ts%10;
            ts/=10;
        }
        if (ls==a&&ss(a))
        {
            cout<<a<<endl;
        }
    }
}

by EmptyAlien @ 2024-11-13 12:39:56

你的做法有问题,可以参考题解


by michaelwanghaoyu @ 2024-11-14 20:51:21

@EmptyAlien xx


|