PersonalCorpus 版 (精华区)

寄信人: ooze (烂泥~苦读武侠中)
标  题: 543
发信站: 哈工大紫丁香 (2002年06月19日15:14:51 星期三)
来  源: 202.118.239.224 

Your C++ program has solved Ok the problem 543 (Goldbach\'s 
Conjecture)
in 0.390 seconds using as much as 1364 kbytes of virtual memory.

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include <math.h>
#include <ctype.h>

void main()
{
#ifndef ONLINE_JUDGE
    freopen("c:\\uva\\input543.txt","r",stdin);
    freopen("c:\\uva\\output543.txt","w",stdout);
#endif
    char p[1000001];
    int i,j,k,fin;

    memset(p,1,sizeof(p));
    for (i=4;i<1000001;i+=2) p[i]=0;

    for (i=3;i<1000001;i+=2) if (p[i]==1)
        for (j=i+i;j<1000001;j+=i) p[j]=0;
    scanf("%d\n",&k);
    while (k!=0) {
        fin=0;
        for (i=3;i<=k/2;i+=2) if ((p[i]==1)&&(p[k-i]==1)) {
            fin=1; printf("%d = %d + %d\n",k,i,k-i); break;
        }
        if (fin==0) printf("Goldbach's conjecture is wrong.\n");
        scanf("%d\n",&k);
    }
}

※ 来源:·哈工大紫丁香 bbs.hit.edu.cn·[FROM: 202.118.239.224]
--
※ 转寄:.哈工大紫丁香 bbs.hit.edu.cn.[FROM: 202.118.239.224]
[百宝箱] [返回首页] [上级目录] [根目录] [返回顶部] [刷新] [返回]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:1.912毫秒