状态题目:哥德巴赫猜想(Easy)
题目编号:131-哥德巴赫猜想(Easy) [查看该题]
状态: Unaccepted
测评机: Xeond[6]
得分: 20分
提交日期: 2008-8-6 11:16:00
有效耗时: 47毫秒
测试结果1: 通过本测试点|有效耗时47:ms
测试结果2: 测试结果错误.错误结果为:4=2+2
6=3+3
8=3+5
10=3+7
14=3+11
16=3+13
正确结果应为:4=2+2
6=3+3
8=3+5
10=3+7
12=5+7
14=3+11
16=3+13
测试结果3: 测试结果错误.错误结果为:4=2+2
6=3+3
8=3+5
10=3+7
14=3+11
16=3+13
18=5+13
20=3+17
正确结果应为:4=2+2
6=3+3
8=3+5
10=3+7
12=5+7
14=3+11
16=3+13
18=5+13
20=3+17
测试结果4: 测试结果错误.错误结果为:4=2+2
6=3+3
8=3+5
10=3+7
14=3+11
16=3+13
18=5+13
20=3+17
22=3+19
26=3+23
30=7+23
32=3+29
34=3+31
正确结果应为:4=2+2
6=3+3
8=3+5
10=3+7
12=5+7
14=3+11
16=3+13
18=5+13
20=3+17
22=3+19
24=5+19
26=3+23
28=5+23
30=7+23
32=3+29
34=3+31
36=5+31
测试结果5: 测试结果错误.错误结果为:4=2+2
6=3+3
8=3+5
10=3+7
14=3+11
16=3+13
18=5+13
20=3+17
22=3+19
26=3+23
30=7+23
32=3+29
34=3+31
38=7+31
40=3+37
42=5+37
44=3+41
46=3+43
50=3+47
正确结果应为:4=2+2
6=3+3
8=3+5
10=3+7
12=5+7
14=3+11
16=3+13
18=5+13
20=3+17
22=3+19
24=5+19
26=3+23
28=5+23
30=7+23
32=3+29
34=3+31
36=5+31
38=7+31
40=3+37
42=5+37
44=3+41
46=3+43
48=5+43
50=3+47
提交代码:
var
a:array[1..256]of byte;
i,x,j,w,n,p,m:integer;
flagi,flagj:boolean;
begin
read(n);
for i:=2 to n div 2 do
begin
x:=i*2;
for p:=2 to x do
begin
flagi:=true;
for j:=2 to trunc(sqrt(p)) do
if i mod j=0
then flagi:=false;
if flagi
then begin w:=x-p; flagj:=true; end;
for m:=2 to trunc(sqrt(w)) do
if w mod m=0
then flagj:=false;
if (flagj)and(p<>1)and(w<>1)and(flagi)and(p<>0)and(w<>0)and(p<=w)and(a[x]=0)
then begin writeln(x,’=’,p,’+’,w); a[x]:=1; end;
end;
end;
end.
#include<iostream>
#include<cmath>
#include<time.h>
using namespace std;
int p[2501],k,i,j,q,n;
main(){
p[2]=1,k=1;
cin>>n;
memset(p,0,sizeof(p));
double t1,t2;
t1=(double)clock();
for(q=3;q<=2500;q++){
bool flag=true;
for(i=2;i<=long(sqrt(q));i++){
if(q%i==0){
flag=false;
break;
}
}
if(flag){
p[q]=1;
}
}
if(n>=4)
cout<<"4=2+2";
bool wr=false;
for(q=4;q<=n;q+=2){
bool flag=false;
for(i=2;i<=q&&!flag;i++)
if(p[i]==1&&p[q-i]==1)
cout<<endl<<q<<"="<<i<<"+"<<q-i,flag=true;
}
}