【UVA】1210 - Sum of Consecutive Prime Numbers

普通的求区间连续和的问题,一开始以为是区间移动,但是怕UVA数据太严,直接打表,后来发现自己的担心是多余的。

14044972 1210 Sum of Consecutive Prime Numbers Accepted C++ 0.049 2014-08-15 10:30:11

打表的话效率可能不是很高.

AC代码:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<string>
#include<sstream>
#include<ctime>
using namespace std;
#define _PI acos(-1.0)
#define INF (1 << 10)
#define esp 1e-9
#define MOD 100000007
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> pill;
/*===========================================
===========================================*/
#define MAXD 10000 + 1
#define MAX_SIZE 6000000
int Prime_sum[MAXD];
int _count[MAX_SIZE] = {0};
int size = 1;
void Get_Prime(){
    int vis[MAXD] = {0};
    Prime_sum[0] = 0;
    for(int i = 2 ; i < MAXD ; i++)if(!vis[i]){
        if(size == 0)
            Prime_sum[size ++] = i;
        else{
            Prime_sum[size] = Prime_sum[size - 1] + i;
            size++;
        }
        for(int j = i * i ; j < MAXD ; j += i)
            vis[j] = 1;
    }
    return ;
}
void init(){
    Get_Prime();
    for(int i = 1 ; i < size ; i++)
        for(int j = 0 ; j < i ; j++){
            int t = Prime_sum[i] - Prime_sum[j];
            _count[t] ++;
    }
}
int main(){
    init();
    int n;
    while(scanf("%d",&n) && n){
        printf("%d\n",_count[n]);
    }
    return 0;
}

【UVA】1210 - Sum of Consecutive Prime Numbers,布布扣,bubuko.com

时间: 2024-10-25 07:06:00

【UVA】1210 - Sum of Consecutive Prime Numbers的相关文章

UVA 1210 Sum of Consecutive Prime Numbers(数论)

UVA - 1210 Sum of Consecutive Prime Numbers Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Submit Status Description Some positive integers can be represented by a sum of one or more consecutive prime numbers. How many such

POJ 2739 Sum of Consecutive Prime Numbers【素数打表】

解题思路:给定一个数,判定它由几个连续的素数构成,输出这样的种数 用的筛法素数打表 Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20020   Accepted: 10966 Description Some positive integers can be represented by a sum of one or more consecutive

POJ 2739 Sum of Consecutive Prime Numbers( *【素数存表】+暴力枚举 )

Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 19895   Accepted: 10906 Description Some positive integers can be represented by a sum of one or more consecutive prime numbers. How many such representatio

POJ 2739 Sum of Consecutive Prime Numbers(水题)

Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20560   Accepted: 11243 Description Some positive integers can be represented by a sum of one or more consecutive prime numbers. How many such representatio

poj 2739 Sum of Consecutive Prime Numbers 素数 读题 难度:0

Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 19697   Accepted: 10800 Description Some positive integers can be represented by a sum of one or more consecutive prime numbers. How many such representatio

poj 2379 Sum of Consecutive Prime Numbers

Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 24498   Accepted: 13326 Description Some positive integers can be represented by a sum of one or more consecutive prime numbers. How many such representatio

poj 2739 Sum of Consecutive Prime Numbers 尺取法

Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 21924   Accepted: 11996 Description Some positive integers can be represented by a sum of one or more consecutive prime numbers. How many such representatio

Sum of Consecutive Prime Numbers(poj2739)

Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22019   Accepted: 12051 Description Some positive integers can be represented by a sum of one or more consecutive prime numbers. How many such representatio

poj2739 Sum of Consecutive Prime Numbers (素数打表)

D - Sum of Consecutive Prime Numbers Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice POJ 2739 Appoint description: System Crawler (2016-05-05) Description Some