最后一个点mle求调

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

gengyan @ 2024-10-30 13:20:10

#include <bits/stdc++.h>
#define ll long long
using namespace std;
int a, b;
int cnt = 0;
int prime[1000000] = {0};
int notPrime[100000001] = {0};
void soe(int n)
{
    notPrime[1] = 1;
    for (int i = 2; i <= n; i++)
    {
        if (!notPrime[i])
        {
            prime[cnt++] = i;
        }
        for (int j = 0; j < cnt; j++)
        {
            if ((ll)i * prime[j] > n)
                break;
            notPrime[i * prime[j]] = 1;
            if (i % prime[j] == 0)
                break;
        }
    }
}
bool ispalin(int n)
{
    string s = to_string(n);
    string rs = s;
    reverse(rs.begin(), rs.end());
    return s == rs;
}
int main()
{
    cin >> a >> b;
    soe(b);
    for (int i = 0; i < cnt; i++)
    {
        if (prime[i] >= a)
        {
            if (ispalin(prime[i]))
                cout << prime[i] << '\n';
        }
    }
    return 0;
}

by jzjr @ 2024-10-30 13:50:18

不用开到 1e8 捏,

偶数长度的回文数绝对不是质数。


by jzjr @ 2024-10-30 13:50:46

@gengyan


by jzjr @ 2024-10-30 13:52:13

11 除外


by gengyan @ 2024-10-30 14:30:31

@jzjr 过了,跪谢大佬,已关


|