80分两点WA

P1579 哥德巴赫猜想(升级版)

caojiaming @ 2023-05-14 21:31:20

#include <bits/stdc++.h>
using namespace std;
bool isntp[20010];//不是质数为1
int pr[20010],cur=0,n;
void work1()
{
    isntp[0]=1;
    for(int i=2;i<=n;i++)
    {
        if(!isntp[i]) pr[++cur]=i;
        for(int j=1;j<=cur&&pr[j]*i<=n;j++)
        {
            isntp[pr[j]*i]=1;
            if(i%pr[j]==0) break;
        }
    }
}
void work2()
{
    for(int i=1;i<=cur;i++)
    {
        for(int j=i;j<=cur;j++)
        {
            int k=n-pr[i]-pr[j];
            if(!isntp[k])
            {
                printf("%d %d %d",pr[i],pr[j],k);
                return;
            }
        }
    }
}
int main()
{
    scanf("%d",&n);
    work1();
    work2();
    return 0;
}

by lij123 @ 2024-04-22 21:29:09

 for(int j=i;j<=cur;j++)

改成

 for(int j=i;j<=cur-i;j++)

@caojiaming


|