ashore_ @ 2025-01-03 12:58:35
4*5e7+10=200MB,1e8=100MB,总共300+MB啊,我提交后显示我才用了110+MB,这是什么原理
int prime[50000010], a, b, n = 1, k;
char s[15];
bool isprime[100000010];
#include <bits/stdc++.h>
using namespace std;
// const int MOD = 1e9 + 7;
int prime[50000010], a, b, n = 1, k;
char s[15];
bool isprime[100000010];
void get_prime() {
memset(isprime, 1, sizeof(isprime));
isprime[1] = 0;
for (int i = 2; i <= b; ++i) {
if (isprime[i]) prime[n++] = i;
for (int j = 1; j < n && i * prime[j] <= b; ++j) {
isprime[i * prime[j]] = 0;
if (i % prime[j] == 0) break;
}
}
}
bool judge(int x) {
k = 0;
while (x) {
s[k++] = x % 10;
x /= 10;
}
int i = 0, j = k - 1;
while (i < j)
if (s[i] != s[j])
return false;
else
++i, --j;
return true;
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> a >> b;
get_prime();
int i = lower_bound(prime, prime + n, a) - prime;
for (; prime[i] <= b && i < n; ++i) {
if (judge(prime[i])) cout << prime[i] << endl;
}
return 0;
}
by Little_Cancel_Sunny @ 2025-01-03 13:21:18
@ashore_ 有没有可能洛谷是动态内存