lym61 @ 2023-11-03 17:48:06
#include<stdio.h>
#include<stdbool.h>
int prime[2000];
int cur;
bool status[1000000001];
void Euler_s(int n)
{
status[0] = 1; status[1] = 1;
for (int i = 2; i <= n; i++)
{
if (status[i] == 0) prime[++cur] = i;
for (int j = 1; j <= cur; j++)
{
if (i * prime[j] > n) break;
status[i * prime[j]] = 1;
if (i % prime[j] == 0) break;
}
}
}
void isPalindrome(int a)
{
for (int j = 1; j <= cur; j++)
{
int sum = 0, i = 0;
int at = prime[j];
while (sum < at)
{
i = at % 10;
at /= 10;
sum *= 10;
sum += i;
}
if(((sum / 10)== at || sum == at) && (prime[j] >= a))
{
printf("%d\n", prime[j]);
}
}
}
int main()
{
int a, b;
scanf("%d%d", &a, &b);
a=(5<=a)?a:5;
b=(99999999<=b)?99999999:b;
Euler_s(b);
isPalindrome(a);
return 0;
}
by heyx0201 @ 2023-11-03 18:23:48
prime
数组开小了
#include<stdio.h>
#include<stdbool.h>
int prime[6000000];
int cur;
bool status[100000001];
void Euler_s(int n)
{
status[0] = 1; status[1] = 1;
for (int i = 2; i <= n; i++)
{
if (status[i] == 0) prime[++cur] = i;
for (int j = 1; j <= cur; j++)
{
if (i * prime[j] > n) break;
status[i * prime[j]] = 1;
if (i % prime[j] == 0) break;
}
}
}
void isPalindrome(int a)
{
for (int j = 1; j <= cur; j++)
{
int sum = 0, i = 0;
int at = prime[j];
while (sum < at)
{
i = at % 10;
at /= 10;
sum *= 10;
sum += i;
}
if(((sum / 10)== at || sum == at) && (prime[j] >= a))
{
printf("%d\n", prime[j]);
}
}
}
int main()
{
int a, b;
scanf("%d%d", &a, &b);
a=(5<=a)?a:5;
b=(99999999<=b)?99999999:b;
Euler_s(b);
isPalindrome(a);
return 0;
}
by lym61 @ 2023-11-03 20:11:44
@heyx0201 为什么我开2000在vs能跑起来
by heyx0201 @ 2023-11-03 20:23:47
@lym61 样例当然能过
by lym61 @ 2023-11-03 20:42:23
@heyx0201 谢谢!能不能请问一下样例是什么意思
by heyx0201 @ 2023-11-03 20:46:43
@lym61 就是题目里的“输入输出样例”
by lym61 @ 2023-11-03 20:53:04
@heyx0201 但是我在vs输入5到一亿这个范围也能跑
by heyx0201 @ 2023-11-03 20:54:33
@lym61 有时候数组开小会导致奇怪的WA
by lym61 @ 2023-11-03 20:55:45
@heyx0201 这样子的吗,谢谢大佬了!
by chrisDLkk @ 2023-11-19 21:42:41
测评端用的是linux比较严格,所以小数组会爆空间(加油hxd)
by lym61 @ 2023-12-01 00:33:20
@chrisDLkk 这样子的啊,感谢!