UVA Problem(Sum of Consecutive Prime Numbers) 1210 Solution

Problem Solving, UVa

#include <stdio.h>

#include<iostream>

#include<math.h>

#include<algorithm>

#include<cstring>

using namespace std;

bool flag[10001];

int primes[10001],result[10001];

int cnt,s;



void sieve(int n)

{

cnt=0;

primes[cnt++] = 2;

for(int i=3; i<=n; i+=2)

{

if(flag[i] == 0)

{

primes[cnt++] = i;

if(i <= n/i)

{

for(int j=i*i; j<=n; j+=i*2)

flag[j] = 1;

}

}

}



return ;

}



void value() {

//cout<<"p"<<N<<endl;

    for (int i = 0; i < cnt; i++) {

         s = 0;

        for (int j = i; j < cnt; j++) {

            s += primes[j];

            if (s > 10001)

            cout<<"s value"<<s<<endl;

             continue;

            result[s]++;

        }

    }

}



int main() {

   

    int n;

    sieve(10001);

   value();



    while (cin>>n and n>0) {

         cout<<result[n]<<endl;

    }

    return 0;

}

 

0 Comments

You may find interest following article

Complete Guide: Create Laravel Project in Docker Without Local Dependencies

Create Laravel Project Through Docker — No Need to Install PHP, MySQL, or Apache on Your Local Machine In this tutorial, I’ll show you how to create and run a full Laravel project using Docker containers. That means you won’t have to install PHP, MySQL, or Apache locally on your computer. By the end of this guide, you’ll have a fully functional Laravel development...