Joker_1212 @ 2022-07-12 07:56:35
源码如下:
/* By @Joker_1212 */
#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define maxn 20000
using namespace std;
int is_primer[maxn + 5], primer[maxn / 10 * 8 + 5], cnt = 0;
void pre()
{
for (int i = 0; i <= maxn; ++i)
is_primer[i] = 1;
is_primer[0] = is_primer[1] = 0;
for (int i = 2; i <= maxn; ++i)
{
if (is_primer[i])
primer[cnt++] = i;
for (int j = 0; j < cnt && i * primer[j] <= maxn; ++j)
{
is_primer[i * primer[j]] = 0;
if (i % primer[j] == 0)
break;
}
}
}
int main()
{
#ifdef LOCAL
freopen("./in.in", "rb", stdin);
#endif
pre();
int n;
scanf("%d", &n);
for (int i = 0; i < cnt; ++i)
for (int j = i; j < cnt; ++j)
if (is_primer[n - primer[i] - primer[j]] && (n - primer[i] - primer[j]) >= primer[j])
return printf("%d %d %d", primer[i], primer[j], n - primer[i] - primer[j]) & 0;
}
结果5个点 RE,错误信息都是 Segmentation fault with invaild memory reference
,求调
by William_Takazaki @ 2022-07-12 08:07:17
用freopen干吗?
by xqqQwQ_ @ 2022-07-12 08:08:13
@William_wyx
他那个本地才会FREOPEN
有ifdef
by Joker_1212 @ 2022-07-12 08:09:17
@William_wyx freopen
只会在本地生效,在洛谷上不会被编译,而且用了 freopen
只会全 WA
(别问我怎么知道的),和 RE
没关系
by William_Takazaki @ 2022-07-12 08:11:01
https://www.luogu.com.cn/paste/f9e5zbkq
by xqqQwQ_ @ 2022-07-12 08:11:04
是不是你n - primer[i] - primer[j]变成负数了,访问了负数下标。
或者数组开小了。
by Joker_1212 @ 2022-07-12 08:13:38
@LiMLE 确实是负数下标的问题,感谢。此帖完结