Super Prime

Super Prime

Time Limit: 5000ms   Memory limit: 65536K  有疑问?点这里^_^

题目描述

We all know, prime is a kind of special number which has no other factors except of 1 and itself.
2,3,5,7,11,13,17,19,23,29 are the top 20 primes.
Now there is a new question about prime:
We call a prime as super prime when and only when which can be represented as the sum of multiple continuous primes. For example: 5=2+3, so 5 is a super prime.
Please program to judge whether a number is a super prime or not.

输入

The first line is an integer T (T<=1000), and then T lines follow.
There is only one positive integer 
N(1<N<100000).

输出

For each case you should output the case number first, and then the word "yes" if the integer N is a super prime, and you should output "no" otherwise.

示例输入

3
5
7
8

示例输出

Case 1: yes
Case 2: no
Case 3: no

提示

 

来源

2012年"浪潮杯"山东省第三届ACM大学生程序设计竞赛(热身赛)
#include <iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
bool flag1[100010];
bool flag2[100010];
int prime[20000],k;
void getprime()
{
    memset(flag1,0,sizeof(flag1));
    flag1[1]=1;
    int i,j;

    for(i=2;i<=100000;i++)
    {
        if(!flag1[i])
        {
            prime[++k]=i;
        }
            for(j=1;j<=k&&i*prime[j]<=100000;j++)      //素数筛;
            {
                flag1[i*prime[j]]=1;
                if(i%prime[j]==0)
                break;
            }

    }


}
void super()
{
    int g;

    for(int i=1;i<k;i++)
    {
       g=prime[i];
        for(int j=i+1;(g=g+prime[j])<=100000;j++)    //暴力超级素数;
        {

            if(!flag1[g])
            {
                flag2[g]=1;
            }
        }
    }
}
int main()
{
      k=0;
   getprime();
   super();
   int t,n,l;
   while(cin>>t)
   {
       l=0;
       while(t--)
       {
           cin>>n;
           printf("Case %d: ",++l);
           if(flag2[n])
           printf("yes\n");
           else
           printf("no\n");
       }
   }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值