五十分。。不知为何,求帮助,谢谢

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

xikiy @ 2018-07-08 14:59:21

include<bits/stdc++.h>

using namespace std; int zt(int x) { int i; for(i=2;i<=sqrt(x);++i)
if(x%i==0)
return 0;
return 1; } int a[10001]; int main() { int n,i,j,k,sum=0,x=0,y; cin>>n; for(i=2;i<=n;++i) { if(zt(i)==1) a[++sum]=i; } for(i=1;i<=sum;++i) for(j=1;j<=sum;++j) { if(zt(n-a[i]-a[j])==1) { cout<<a[i]<<" "<<a[j]<<" "<<n-a[i]-a[j]; return 0; } } return 0; }


by Chloris @ 2018-07-08 15:24:17

markdown

了解一下


by Siyuan @ 2018-07-08 15:28:59

#include<bits/stdc++.h>
using namespace std;
int zt(int x) {
    int i;
    for(i=2; i<=sqrt(x); ++i)
        if(x%i==0)
            return 0;
    return 1;
}
int a[10001];
int main() {
    int n,i,j,k,sum=0,x=0,y;
    cin>>n;
    for(i=2; i<=n; ++i) {
        if(zt(i)==1) a[++sum]=i;
    }
    for(i=1; i<=sum; ++i)
        for(j=1; j<=sum; ++j) {
            if(zt(n-a[i]-a[j])==1) {
                cout<<a[i]<<" "<<a[j]<<" "<<n-a[i]-a[j];
                return 0;
            }
        }
    return 0;
}

by xikiy @ 2018-07-08 18:16:45

@siyuan 能给一个正解吗?


by xikiy @ 2018-07-08 18:17:00

@Chloristendika 能具体一点吗?


by 白烛葵 @ 2018-07-19 08:16:49

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,n,j,k,a[20001]={0};
    cin>>n;
    for(i=2;i<=n;i++)
    {
        for(k=2;k<=sqrt(i);k++)
        if(i%k==0)
        break;
        if(k>sqrt(i))
        a[i]=1;
    }
    for(i=2;i<=n;i++)
    for(k=2;k<=n;k++)
    if(a[i]==1&&a[k]==1&&a[n-i-k]==1)
    {
        cout<<i<<" "<<k<<" "<<n-i-k;
        return 0;
    }
}

by 白烛葵 @ 2018-07-19 08:17:18

水题一个


|