PersonalCorpus 版 (精华区)

Your C++ program has solved Ok the problem 406 (Prime Cuts)
in 0.370 seconds using as much as 396 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\\input406.txt","r",stdin);
    freopen("c:\\uva\\output406.txt","w",stdout);
#endif

    int p[170];
    int i,j,k,c,n,mark;

    p[0]=1;p[1]=2; k=1; p[169]=1001;
    for (i=3;i<1000;i++) {
        mark=0;
        for(j=1;j<=k;j++) if (i%p[j]==0) { mark=1; break; }
        if (mark==0) { k++; p[k]=i; }
    }
    while (scanf("%d%d\n",&n,&c)==2) {
        printf("%d %d:",n,c);
        for (i=0;i<169;i++) if (p[i]>n) break;
        if (i%2==0) {
            for (j=i/2-c;j<i/2+c;j++) if ((j>=0)&&(j<i)) printf(" %d",
p[j]);
        }else {
            for (j=i/2-c+1;j<i/2+c;j++) if ((j>=0)&&(j<i)) printf(" 
%d",p[j]);
        }
        printf("\n\n");
    }

}
[百宝箱] [返回首页] [上级目录] [根目录] [返回顶部] [刷新] [返回]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:3.331毫秒