Search is not available for this dataset
name
stringlengths
2
112
description
stringlengths
29
13k
source
int64
1
7
difficulty
int64
0
25
solution
stringlengths
7
983k
language
stringclasses
4 values
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
//Sum of Prime Numbers #include<bits/stdc++.h> using namespace std; typedef long long ll; vector<ll> p; int main(){ p.push_back(2); for(int i=3; p.size()!=10000; i+=2){ bool flag=true; for(int j=0; j<p.size(); j++){ if(i%p[j]==0){ flag=false; break; } } if(flag)p.push_b...
CPP
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
#include <cstdio> #include <cstring> #define N 110000 using namespace std; int main(void){ int p[N] = {0}; int sum[10001]={0}, cnt=0; for (int i=2; i<N; i++){ if (p[i]==-1) continue; p[i]=0; cnt++; sum[cnt] = sum[cnt-1]+i; for (int j=i; j<N; j+=i){ p[j]=-1; } } while (scanf...
CPP
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
#include<iostream> #include<vector> using namespace std; inline void prime(int *p, int n){ fill(p, p+n, 1); p[0] = 0; p[1] = 0; for(int i=2; i<=n; i++){ for(int j=2; i*j<=n; j++){ p[i*j] = 0; } } } int main(){ int cnt, p[105001], sum, n; vector<int> vc; prime(p, 105000); cnt = 0; sum...
CPP
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
#include <iostream> #include <vector> #include <cmath> using namespace std; int main() { int n; vector<int> pri(1000000, 1); vector<int> p_sum; pri[0] = 0; pri[1] = 0; for(int i = 2; i < sqrt(1000000); i++) { for(int j = i*i; j < 1000000; j+=i) { pri[j] = 0; } } int cnt = 0; p_sum.pus...
CPP
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
#include <cmath> #include <iostream> #include <vector> typedef std::vector <int> vi; vi PRIMES; vi prime(int n){ int i=0,j=1,h=(n+1)/2,x; vi s(h),p; while(j<=n){ s[i++]=j; j+=2; } for (i=1;i<=(int)pow(n,0.5);i++) if (x=s[i]) for (j=i+x;j<h;j+=x) s[j]=0; s[0]=2; for (i=0;i<h;i++) if(s[i]!=0) p.push_back(s[i...
CPP
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
Max=1000000 Sqrt=1000 def prime_number(): count=[] prime=[True for i in range(Max)] for i in range(4,Max,2): prime[i]=False for i in range(3,Sqrt,2): if prime[i]==True: for j in range(i*2,Max,i): prime[j]=False for k in range(2,Max): if prim...
PYTHON3
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
#include <iostream> using namespace std; int main(){ const int NUM = 1e6; bool prime[NUM]; for(int i=2;i<NUM;i++) prime[i] = true; for(int i=2;i*i<NUM;i++) for(int k=2;i*k<NUM;k++) prime[i*k]=false; int n,c; while(cin>>n){ if(!n)break;c=0; for(int i=2,k=0;k<n;i++)if(prime[i])c+=i,k++;...
CPP
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
#include <iostream> #include <vector> using namespace std; bool isprime(int n) { for (int i = 2; i * i <= n; i++) if (n % i == 0) return false; return n != 1; } int main() { vector<long long> v; int n = 0; for (int i = 2; n <= 10000; i++) { if (isprime(i)) { v.push_back(i); n++; } } while (cin ...
CPP
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
primes = [0, 0] + [1] * 150000 for i in range(2, 388): if primes[i]: for j in range(i*i, 150001, i): primes[j] = 0 values = [i for i, v in enumerate(primes) if v] while True: n = int(input()) if n == 0: break print(sum(values[:n]))
PYTHON3
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
#include<iostream> #include<vector> #define N 300000 using namespace std; bool p[N]; int num[N]; int main(){ for(int i=0;i<N;i++)p[i] = true; p[0] = p[1] = false; for(int i=2;i*i<N;i++){ if(p[i]){ for(int j=2*i;j<N;j+=i)p[j] = false; } } vector<int> v; int sum = 0,pos = 0; while(v.size...
CPP
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
#include<iostream> using namespace std; int ans[10001],size=2; bool isP(int x){ if(x<=1)return false; for(int i=2;i*i<=x;i++){ if(x%i==0)return false; } return true; } int main(){ ans[1]=2; for(int i=3;size<10001;i++){ if(isP(i)){ ans[size]=ans[size-1]+i; size++; } } int n; whi...
CPP
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
import java.util.*; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); ArrayList<Integer> index = new ArrayList<Integer>(); ArrayList<Integer> search = new ArrayList<Integer>(); for(int i=2; i<=110000; i++) search.add(i); index.add(2); while(index.get(index.s...
JAVA
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
import sys PRIMES=[] SIEVES=[] def sieve(max_number): numbers = range(1, max_number + 2, 2) mroot = int(max_number ** 0.5)+1 half = len(numbers) numbers[0]=0 for i in range(0, half): x = numbers[i] if x > mroot: break if x and i + x < half: numbers[i + x: half: x...
PYTHON
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
#include<iostream> using namespace std; int main(){ bool num[1000001] = {false}; for(int i=2; i<1000; i++) if(!num[i]) for(int j=i*i; j<1000001; j+=i) num[j] = true; int n; while(cin >>n,n){ int ans = 0; for(int i=2; n>0; i++) if(!num[i]){ans+=i;n--;} cout <<ans<<endl; } return 0; }
CPP
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
#include <stdio.h> #define NN 999999 int main(){ int i,j,n,sum; bool prime[NN]; for(i=0;i<NN;i++) prime[i]=true; while(1){ sum=0;n=0; scanf("%d",&n); if(!n) break; for(i=2;i<NN;i++){ for(j=i*2;j<NN;j=j+i) prime[j]=false; } for(i=2,j=0;j<n;i++){ if(prime[i]==true){ sum+=i; j++; } } p...
CPP
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
def isPrime(x): if x == 2: return True if x < 2 or x % 2 == 0: return False i, root_x = 3, int(pow(x, 0.5)) while i <= root_x: if x % i == 0: return False i += 2 return True primes = [2] for i in range(3, 104730): if isPrime(i): primes.append(...
PYTHON3
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
#include <iostream> using namespace std; int main(){ bool is_prime[1000000]; is_prime[0]=is_prime[1]=false; for(int i=2;i<1000000;i++){ is_prime[i]=true; } for(int i=0;i*i<1000000;i++){ if(is_prime[i]){ for(int j=i*i;j<1000000;j+=i){ is_prime[j]=false; } } } while(1){ int a=0; cin>>a; int cu...
CPP
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
#include<stdio.h> #include<stdlib.h> #include<string.h> #include<math.h> const int max=104729; char so[104730]; int main(){ int i,j,n,s; memset(so,0,sizeof(so)); so[0]=so[1]=1; for(i=2;i*i<=max;i++){ for(j=2*i;j<=max;j+=i){ so[j]=1; } } while(0<=scanf("%d",&n)){ if(n==0)break; s=0; for(i=1;n;...
CPP
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
#include <iostream> #define MAX 1000000 using namespace std; int main(){ bool p[MAX]; p[0] = p[1] = false; for(int i=2;i<MAX;i++)p[i] = true; for(int i=2;i<MAX;i++){ if(p[i]){ for(int j=i+i;j<MAX;j=j+i){ p[j] = false; } } } int n; while (cin >> n,n){ int sum = 0; ...
CPP
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int[] pri = new int[260000]; for(int i=2;i<=250000;i++){ pri[i] = i; } for(int i=2;i<=300000;i++){ for(int j=i+i;j<=250000;j+=i){ pri[j]=0; } } while(true){ int n ...
JAVA
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.ArrayList; public class Main { public static void main(String[] args) throws Exception{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); while(true){ int numOfPrimeNumbers = Integer.parseInt(br.readLine()...
JAVA
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
#include <bits/stdc++.h> using namespace std; using db = double; using ll = long long; using vi = vector <int>; #define op operator #define pb push_back const int N = 2e5L + 11; int p[N]; int main() { iota(p, p + N, 0); for(int i = 2; i < N; i ++) if(p[i] == i) for(int j = i; j < N; j += i) p[j] = i; ios :: sy...
CPP
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
#include <iostream> #include <vector> using namespace std; int main() { vector <bool> prime(110000, false); prime[2] = true; for (int i = 3; i < 110000; i += 2) { prime[i] = true; } for (int i = 3; i < 110000; i += 2) { for (int j = i + i; j <= 110000; j += i) { prime[j] = false; } } int n; while (cin...
CPP
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
#include <cstdio> #include <cstring> using namespace std; const int PMAX = 120000; int main() { bool isnp[PMAX+1]; int p[10000]; int x; memset(isnp, 0, sizeof(bool)*(PMAX+1)); for (int i=2; i*i<=PMAX; i++) { if (!isnp[i]) { for (int j=2*i; j<=PMAX; j+=i) { isnp[j] = true; } } }...
CPP
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
#include<iostream> #include<vector> #include<cmath> using namespace std; int main(){ vector<int>pri; pri.push_back(2); for(int i=3;;i+=2){ int flag=1; for(int j=2;j<=sqrt(i);j++){ if(i%j==0){ flag=0; break; } } if(flag) pri.push_back(i); if(pri.size()==10000) break; ...
CPP
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
import math prime = [0 for i in range(11000)] k = 0 r = 104900 sqrt = int(math.sqrt(r)) p = [1]*r p[0] = 0 for i in range(1,sqrt): if p[i]: prime[k] = i+1 k += 1 l = i for j in range(2*i+1,r,i+1): p[j] = 0 for i in range(l+1,r): if p[i]: prime[k] = i+1 ...
PYTHON
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
def sieve(n): a = range(n) a[:2] = None, None for i in range(2, n): if i ** 2 >= n: break if not a[i]: continue for i in range(i ** 2, n, i): a[i] = None return [v for v in a if v] def partialsum(a): b = [0] + a for i in range(len(a)): b[i + 1] += b[i...
PYTHON
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
#include <iostream> #include <stdio.h> using namespace std; int f[110000],pr[11000]; int main() { int n=0,i,j,s=0; for (i=2;i<110000;i++) { if (f[i]==0) { s+=i; pr[n++]=s; for (j=i;j<110000;j+=i) f[j]=1;} } while(cin >> n) { if (n==0) break; cout << pr[n-1] << endl; } return 0; }
CPP
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
def prime_table(n): list = [True for _ in xrange(n + 1)] i = 2 while i * i <= n: if list[i]: j = i + i while j <= n: list[j] = False j += i i += 1 table = [i for i in xrange(n + 1) if list[i] and i >= 2] return table table = prime_table(105000) while True: n = int(raw...
PYTHON
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
#include <cstdio> #include <vector> using namespace std; int main() { vector<int> prime; int n; prime.push_back(2); for(int i = 3; prime.size() < 10000; i += 2){ for (int j = 0; j < prime.size() ;j++){ if (i%prime[j] == 0){ break; } if (j == prime.size()-1){ prime.push_back(i); } } } ...
CPP
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
s = [0] M = 104850 p = [1]*M S = 0 for i in range(2,M): if p[i]: for j in range(i*i,M,i): p[j] = 0 S += i; s.append(S) while 1: n = input() if n==0: break print s[n]
PYTHON
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
import sys PRIMES=[] SIEVES=[] def sieve(m): N=range(1,m+2,2) r=int(m**.5)+1 h=len(N) N[0]=0 for i in range(h): x=N[i] if x>r: break if x and i+x<h: N[i+x:h:x]=[0] * ((h-1-i-x)/x+1) return N def prime(n): global SIEVES if SIEVES==[]: SIEVES=sieve(n) ...
PYTHON
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
#include<bits/stdc++.h> using namespace std; int P[10010]; int sum[10010]={0}; void prime() { int i=3,j,k,cnt=1; P[0] = 2; while(cnt < 10005){ k=0; for(j=3;j<=sqrt(i);j+=2){ if(i%j==0){ k=1; break; } } if(k==0) { P[cnt] = i; cnt++; } i+=2; } sum[0] = P[0]; ...
CPP
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
#include<iostream> #include<cstdio> #include<algorithm> #include<cmath> using namespace std; int j; int prime(){ int k,fg=0; while(1){ if(j%2==0){ fg=1; j++; } else{ k=3; while(k<=sqrt(j)){ if(j%k==0){ fg=1; j++; break; } k+=2; } } if(fg==0){ j++; return j-1...
CPP
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
import java.util.*; import java.io.*; import java.awt.geom.*; import java.math.*; public class Main { static final Scanner in = new Scanner(System.in); static final PrintWriter out = new PrintWriter(System.out,false); static ArrayList<Integer> ps; static boolean solve() { int n = in.nextInt(); if (n == 0) r...
JAVA
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
#include<iostream> #include<vector> using namespace std; int main(){ int dt[150000]; dt[0]=0; dt[1]=0; for(int i=2;i<150000;i++){ dt[i]=1; } for(int i=2;i<750;i++){ for(int j=2*i;j<150000;j+=i){ dt[j]=0; } } vector<int> prime; for(int i=0;prime.size()<10001;i++){ if(dt[i]==1){ prime.push_back(i)...
CPP
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
#include<iostream> #include<cmath> using namespace std; int x[1000000], y[100000], n, cnt; int main() { for (int i = 2; i < 200000; i++) { for (int j = 2; j <= sqrt(i); j++) { if (i%j == 0) { goto E; } } x[i] = 1; E:; } for (int i = 0; i < 200000; i++) { if (x[i] == 1) { cnt++; y[cnt] = y[cnt - 1] + i; }...
CPP
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
#include <stdio.h> int a[2000000]; int main(){ int n; for(int i = 0; i < 2000000; i++){ a[i] = 1; } for(int i = 2; i < 2000000; i++){ if(a[i]){ for(int j = i * 2;j < 2000000; j = j + i){ a[j] = 0; } } } scanf("%d",&n); while(n != 0){ long int ans = 0; for(int i = 2; i < 2000000; i++){ i...
CPP
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
#include<iostream> #include<cmath> using namespace std; bool memo[104730]={false}; void prime(void){ bool flag; memo[2]=true; for(int i=3;i<104730;i=i+2){ flag=true; for(int j=3;j<=sqrt((double)i);j=j+2){ if(i%j==0){ flag=false; break; } } if(flag==true){ memo[i]=true; } } return; ...
CPP
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
#include <cstdio> #include <cstdlib> #include <numeric> #include <vector> using namespace std; vector<int> sieve(int n) { vector<int> res(1, 2); vector<bool> prime(n, true); for(int i = 3; i < n; i += 2) { if(prime[i]) { res.push_back(i); for(int j = i * 3; j < n; j += i * 2) prime[j] = false; } } ...
CPP
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
#include<iostream> #include<cmath> using namespace std; typedef long long ll; ll prime[1000001]; ll length = 0; void insert(ll p) { prime[length] = p; length++; return; } int main() { insert(2); for (ll i = 3; i < 1000000; i += 2) { for (ll j = 0; j < length; j++) if (i%prime[j] == 0)goto cont; else if (prime...
CPP
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
import java.io.*; import java.util.*; class Main{ public static void main(String[] args){ BufferedReader sc=new BufferedReader(new InputStreamReader(System.in)); LinkedList<Integer> list = new LinkedList<Integer>(); boolean[] prime = new boolean[110000]; int[] s = new int[10000]; prime[0] = true; prime[1] = t...
JAVA
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
#include <cmath> #include <iostream> #include <vector> typedef std::vector <int> vi; vi PRIMES; vi prime(int n){ vi s,p; int i,j,x,h; for (i=1;i<=n;i+=2) s.push_back(i); h=s.size(); s[0]=0; for (i=1;i<=(int)pow(n,0.5);i++) if (x=s[i]) for (j=i+x;j<h;j+=x) s[j]=0; s[0]=2; for (i=0;i<h;i++)...
CPP
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
import java.util.Scanner; public class Main { public static void main(String[] args){ Scanner scan = null; try{ int num; int[] prime = new int[10000]; prime[0] = 2; for(int i = 3 ,j = 1;j <prime.length;i += 2){ boolean check = false; for(int k = 3; k < i /2; k += 2){ if(i % k ==0){ ...
JAVA
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
//Volume0-0053 import java.util.Scanner; public class Main { //declare private static final int PRM_MAX = 104730, PRM_NUM = 10001; private static boolean [] prm_table = new boolean[PRM_MAX]; private static int [] prm_sum = new int [PRM_NUM]; ...
JAVA
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
import sys n = 104730 a = [True] * n a[0] = a[1] = False for i in xrange(2,n): if(a[i]): for j in xrange(i+i, n, i): a[j] = False a = [i[0] for i in enumerate(a) if i[1]] for s in sys.stdin: n = int(s) if n == 0: exit() print(sum(a[:n]))
PYTHON
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
#include <cmath> #include <iostream> #include <vector> typedef std::vector <int> vi; vi P; vi prime(int n){ int i=0,j=1,h=(n+1)/2,x,r=(int)pow(n,.5); vi s(h),p(1); while(j<=n){ s[i++]=j; j+=2; } p[0]=2; for (i=1;i<h;i++) if (x=s[i]){ p.push_back(x); if (i<=r) for (j=x*x/2;j<h;j+=x) s[j]=0; } return...
CPP
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
public class Main{ static int N = 1000001; public void run(java.io.InputStream in, java.io.PrintStream out){ java.util.Scanner sc = new java.util.Scanner(in); int[] p; int pn, i, n, sum; p = new int[N / 6]; pn = getprime(p); for(;;){ n = sc.nextInt(); if(n == 0)break; sum...
JAVA
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
#include<stdio.h> int table[500000]; int prime[100000]; int main(){ table[0]=-1; table[1]=-1; for(int i=2;i<500000;i++){ if(table[i]!=-1){ table[i]=1; for(int j=i*2;j<500000;j+=i){ table[j]=-1; } } } int now=0; for(int i=0;i<500...
CPP
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
import sys f = sys.stdin def create_prime(n): prime = [1] * (n + 1) prime[:2] = [0, 0] for i in range(len(prime)): if prime[i]: for j in range(2 * i, len(prime), i): prime[j] = 0 return prime prime = create_prime(200000) while True: n = int(f.readline()) i...
PYTHON3
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
import java.util.*; public class Main{ static Scanner kbd = new Scanner(System.in); public static void main(String[] args){ int[] p = new int[1000000]; setP(p); while(kbd.hasNext()){ int n = kbd.nextInt(); if(n!=0) solve(p, n); } } static void solve(int[] p, int n){ int sum=0, i; for(i=...
JAVA
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
import java.util.ArrayList; import java.util.Scanner; public class Main { static ArrayList<Integer> list=new ArrayList<>(); static boolean[] prime=new boolean[104730]; static void eratos() { for(int i=2; i<104730; i++) { prime[i]=true; } for(int i=2; i<104730; i++) { if(prime[i]) { list.add(i); ...
JAVA
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int[] sum = new int[10001]; int number = 1; ...
JAVA
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
#include <iostream> using namespace std; int main() { int num[104730] = {0}, Pnum[10000], n, ans; int k = 0; for (int i = 2; i < 104730; i++) { if (!(num[i])) { Pnum[k] = i; k++; for (int j = i + i; j < 104730; j+=i) { num[j] = 1; } } } while (cin >> n) { if (n == 0) break; ans = 0; ...
CPP
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
from itertools import * n=104730;a=list(range(n));a[:2]=0,0 for i in range(2,323):a[i*2::i]=[0]*len(a[i*2::i]) p=list(compress(range(n),a)) print('\n'.join(str(sum(p[:int(e)]))for e in iter(input,'0')))
PYTHON3
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
import itertools n=104730;a=list(range(n));a[:2]=0,0 for i in range(2,323): a[i*2::i]=[0]*len(a[i*2::i]) p=list(itertools.compress(range(n),a)) for e in iter(input,'0'):print(sum(p[:int(e)]))
PYTHON3
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
#include <iostream> using namespace std; bool t[999999] = {false}; int main() { int n, c, i, j, d; t[0] = true; for (i = 2; i * i <= 999999; i++) { if (!t[i-1]) { for (j = i+i; j <= 999999; j+=i) t[j-1] = true; } } while (cin >> n, n) { c = 0; d = 1; for (i = 1; d <= n; i++) { if (!t[i]) ...
CPP
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
#include <iostream> #include <vector> using namespace std; #define N 104730 bool table[N]; vector<int> prime; int main() { int size = 0; for (int i = 2; i < N; i++) { if (table[i] == false) { for (int j = i; j < N; j += i) { table[j] = true; } prim...
CPP
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
#include<iostream> #include<vector> #define loop(i,a,b) for(long long i=a;i<b;i++) #define rep(i,a) loop(i,0,a) using namespace std; bool prime[7000000]; int main(){ rep(i,7000000)prime[i]=true; prime[0]=prime[1]=false; loop(i,2,10000){ for(long long j=i*2;j<7000000;j+=i)prime[j]=false; } vector<long long> p; ...
CPP
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
def mark(s, x): for i in range(x + x, len(s), x): s[i] = False def sieve(n): s = [True] * n for x in range(2, int(n**0.5) + 1): if s[x]: mark(s, x) return [i for i in range(0,n) if s[i] and i > 1] n = [] while True: tmp = int(input()) if tmp == 0: break n.append(tmp...
PYTHON3
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
#include <iostream> #include <cstdio> using namespace std; #define rep2(x,from,to) for(int x = (from); x < (to); ++(x)) #define rep(x,to) rep2(x,0,to) #define MAX_PRIME 160000 int main() { bool p[MAX_PRIME]; p[0] = p[1] = 0; rep2(i,2,MAX_PRIME) { p[i] = 1; } rep(i,400) { if(p[i]) { for(int j = 2; i * j < MA...
CPP
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
#include <cmath> #include <iostream> using namespace std; int a[20000]; int sum[20000]; int n,s; int main() { a[0] = 2; sum[0] = 2; cin >> n; while(n!=0) { for(int i=1 ; i<n; ++i) { int k = a[i-1] + 1; while(a[i]==0) { while(k%a[s]!=0) { if(a[s]*a[s] > k) { a[i] = k; //cout << i+1 << "...
CPP
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Scanner; public class Main{ static int max = 2000000; static boolean[] isPrime = new boolean[max]; public static void main(String[] args) { aryPrime(); List<Integer> list = new ArrayList<Integer>(); for(int i = 2; i <...
JAVA
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws NumberFormatException, IOException { BufferedReader reader = new BufferedReader(new InputStreamReader( System.in)); StringBuilder builder = new Str...
JAVA
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
import math def pri(n): if n < 2: return False elif n == 2: return True elif n % 2 == 0: return False i = 3 while i <= math.sqrt(n): if n % i == 0: return False i += 2 return True l=[i for i in range(110000)if pri(i) ] while True: n = in...
PYTHON3
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
#include <iostream> #include <vector> using namespace std; int main() { const long N = 1000000; vector<bool> p(N, true); p[0] = p[1] = false; int i, j, n, a, c; for (i = 2; i * i < N; i++) { if (!p[i]) continue; for (j = i * i; j < N; j += i) p[j] = false; } while (cin >> n, n) { a = 0, c = 0; ...
CPP
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
import java.util.*; public class Main { public static void main(String[] args) throws java.io.IOException{ Scanner scan = new Scanner(System.in); while(true){ int n=scan.nextInt(); if(n==0)break; int count=0; int sum=0; for(in...
JAVA
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
import java.util.Scanner; class Main{ public static void main(String[] args) { Scanner sc=new Scanner(System.in); int input=0; int sosuko=0; long wa=0l; int genzai=0; boolean ss=false; while(sc.hasNext()) { input=sc.nextInt(); sosuko=0; wa=0l; genzai=0; if(input>=1) { wa+=2; genz...
JAVA
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
#include<cstdio> #include<vector> using namespace std; int main(){ int n; vector<bool> ar(1000*1000+1,true); for(int i=2;i<=1000;i++){ if(ar[i])for(int j=i*i;j<ar.size();j+=i)ar[j]=false; } vector<long> ps; for(int i=2;i<ar.size();i++){ if(...
CPP
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
#include <iostream> using namespace std; /** Problem0044 : Prime Number II **/ #define MAX 110000 int main() { bool prime[MAX]; int input; unsigned sum, num; for (int i=0; i<MAX; i++) prime[i] = true; prime[0] = false; prime[1] = false; for (int i=2; i<MAX; i++) { if (prime[i]) { for (int j=2; i*j<...
CPP
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
#include<stdio.h> #include<math.h> int main(){ bool N[10002]; //for(int i=0;i<10001;i++) //N[i]=false; int R[10003]={}; int H=2; for(int i=3;H<=10001;i+=2) {bool G=true; for(int j=2;j<=sqrt((double)i);j++) {if(i%j==0){G=false;break;}} if(G==true){R[H]=i;H++;} } //N[2]=true;N[3]=true; R[1]=2;R[0]=0; int n; while(1){...
CPP
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; public class Main { /** * @param args * @throws IOException * @throws NumberFormatException */ public static void main(String[] args) throws NumberFormatException, IOException { // TODO...
JAVA
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; public class Main { public static void main(String[] args) { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String line = null; // エラトステネスの篩 int MAX = 1000000; i...
JAVA
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
import java.io.BufferedReader; import java.io.InputStreamReader; public class Main { static final int MAX_NUM_OF_PRIME_NUMBERS = 10000; public static void main(String[] args) throws Exception{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); while(true){ int numOfPrimeNumbers = Int...
JAVA
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
#include <iostream> using namespace std; #define MAX 10005 #define MAXL 1000000 //const MAX = 10001; int ans[MAX]; int main(){ int n; static bool c[MAXL]={true, true}; for(int i = 2;i < MAXL;i++){ if(!c[i]){ for(int j = 2;i*j < MAXL;j++)c[i*j] = true; } } int j = 1; for(int i = 1;j < MAX;i++){ if(!c[i]...
CPP
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
#include<cstdio> using namespace std; bool prime[500000]; void check(){ for(int i = 3; i < 400000; i+=2){ if(prime[i]){ for(int j = i*2; j< 400000; j+=i){ prime[j] = false; } } } } int main(void){ int n; for(int i = 3; i < 400000; i+=2){ prime[i] = true; } prime[2] = true; check(); whi...
CPP
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
import java.util.*; import java.io.*; public class Main{ public static void main(String[] args){ Scanner stdIn = new Scanner(System.in); Map<Integer, Integer> prime = new LinkedHashMap<Integer, Integer>(); List<Integer> result = new ArrayList<Integer>(); prime.put(1,2); prime.put(2,5); int[] p = new int[...
JAVA
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); boolean[] p = new boolean[105001]; for (int i = 0; i <= 105000; i++) { p[i] = true; } for (int i = 2; i <= 325; i++) { for (int j = i * 2; j <= 105000; j += i) { p[j] = false...
JAVA
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
#include <iostream> using namespace std; int main() { int data[150000] = {}; int size = sizeof(data) / sizeof(int); for (int i = 2; i < size; ++i) { for (int j = i * 2; j < size; j += i) data[j] = 1; } while (true) { int n; cin >> n; if (n == 0) break; int ans = 0; for...
CPP
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
#include<iostream> #include<math.h> using namespace std; int main() { bool prime[500000] = { false }; for (int i = 2; i <= sqrt(500000); i++) { if (!prime[i]) { for (int j = 2; j*i <= 500000; j++) { prime[j*i] = true; } } } int n; unsigned int sum; while (cin >> n) { if (n == 0)break; sum = 0; i...
CPP
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; class Main{ static boolean[] ints=new boolean[104729+1]; static int[] primes=new int[10000+1]; static void makePrimes(){//System.out.println("ee"); ints[0]=true;ints[1]=true; ...
JAVA
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
#include<iostream> using namespace std; int main(){ bool num[1000000] = {0}; for(int i=2; i<1000; i++){ if(!num[i]){ for(int j=i*i; j<1000000; j+=i){num[j] = 1;} } } for(;;){ int n,sum = 0; cin >>n; if(n == 0){break;} for(int i=2; n>0; i++){ if(!num[i]){n--;sum+=i;} } cout <<sum<<endl; } ret...
CPP
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
#include<iostream> #include<cmath> using namespace std; bool prime(int x){ for(int i=2;i<=sqrt((double)x);i++){ if(x%i==0)return false; } return true; } int main(){ int n; while(cin>>n,n){ int sum=0; for(int i=2;n>=1;i++){ if(prime(i)){sum+=i;n--;} } cout<<sum<<endl; } }
CPP
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
//Volume0-0053 import java.util.Scanner; public class Main { //declare private static final int PRM_MAX = 104730, PRM_NUM = 10001; private static boolean [] prm_table = new boolean[PRM_MAX]; private static int [] prm_sum = new int [PRM_NUM]; ...
JAVA
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
def get_input(): while True: try: yield ''.join(input()) except EOFError: break MAX = 105000 primes = list() for i in range(MAX): primes.append(True) primes[0] = False primes[1] = False for i in range(2, MAX): j = i + i while j < MAX: primes[j] = False ...
PYTHON3
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
def prime(t): i=2 while i**2<=t: if t%i==0: return 0 i+=1 return 1 l=[] for i in range(2,104740): if prime(i): l.append(i) while 1: n=int(raw_input()) if n==0: break ans=0 while n>0: n-=1 ans+=l[n] print ans
PYTHON
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
#include<iostream> using namespace std; int main(){ bool num[1000000]={true,true}; for(int i=2; i<1000; i++) if(!num[i]) for(int j=i*i; j<1000000; j+=i) num[j] = true; int n; while(cin >>n,n){ int ans = 0; for(int i=2; n>0; i++){ if(!num[i]){ ans+=i; n--; } } cout <<ans<...
CPP
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
#include<iostream> #include<cmath> #define NUM 1000000 using namespace std; int main(){ int n, prime[NUM+1], p[NUM+1], count, sum; prime[1]=0; for(int i=2; i<NUM+1; i++){ prime[i] = 1; p[i-2]=0; } for(int i=2; i<=NUM/2; i++){ for(int j=2; i*j <= NUM; j++){ prime[i*j]=0; } } co...
CPP
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
#include <cstdio> bool prime[104730]; int main() { for(int i=2;i*i<=104729;i++) for(int j=i*2;j<=104729;j+=i)prime[j]=true; int n; while(scanf("%d",&n),n) { int p=0,sum=0; for(int i=2;i<=104729;i++) { if(!prime[i])sum+=i,p++; if(p==n)break; } printf("%d\n",sum); } }
CPP
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
#include <iostream> #include <vector> using namespace std; typedef unsigned long long int lli; vector<lli> p; int main(void){ bool ps[200000]; for(int i=0;i<200000;i++)ps[i]=true; ps[0]=ps[1]=false; p.push_back(0); for(int i=2;i<200000;i++){ if(ps[i]){ for(int j=2*i;j<200000;j+=i) ps[j]=false; p.push_back...
CPP
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
#include <iostream> #include <vector> using namespace std; #define MAX 10000000 typedef long long ll; bool prime[MAX]; void calcPrime(){ for( ll i = 2; i < MAX; i++ ) prime[i] = true; for( ll i = 2; i < MAX; i++ ){ if( prime[i] ){ for( ll j = i+i; j < MAX; j += i ) prime[j] = false; } } } int main(){ calc...
CPP
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
import math def pri(n): l =[True] * n l[0] = l[1] = False for i in range(2,n): if l[i]: for j in range(i*2, n, i): l[j] = False return l n=105000 s=pri(n) l=[i for i in range(n) if s[i]] while True: n = int(input()) if n == 0: break print(sum(l[:n]))
PYTHON3
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
#include<cstdio> int p[1<<17],s,i,n; int main(){for(i=2;i<1<<17;i++)for(s=2;!p[i]&&i*s<1<<17;p[i*s++]++);for(;scanf("%d",&n),n;printf("%d\n",s))for(i=2,s=0;!p[i]?s+=i,n--:n,n;i++);}
CPP
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
#define _CRT_SECURE_NO_WARNINGS #include "bits/stdc++.h" using namespace std; int const N = 10010; int ans[N]; bool isprime(int x){ for (int i = 2; i*i <= x; i++){ if (x%i == 0) return false; } return true; } int main(int argc, char ** argv) { int k = 0, i = 2; ans[0] = 0; while (k !=...
CPP
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
#include <iostream> using namespace std; int main(void){ int prime[10002]; int sum[10002]; prime[1] = 2; prime[2] = 3; sum[1] = 2; sum[2] = 5; int ptr=3; for(int num=5; ptr<=10000; num++){ bool f = false; for(int i=1; i<ptr; i++){ if(prime[i]*prime[i] > num){ break; } if(num%prime[i]==0) { ...
CPP
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
#include <stdio.h> int s[1000001]; int p[1000001]; int main(void) { int i, j, k; int n; for (i = 0; i <= 1000000; i++){ s[i] = 1; } s[0] = s[1] = 0; for (i = 2; i * i <= 1000000; i++){ if (s[i] == 0) continue; for (j = i * i; j <= 1000000; j += i){ s[j] = 0; } } k = 2; p[1] = 2; for (i = 3; i...
CPP
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
#include<cstdio> #include<iostream> #include<algorithm> #include<cstring> #include<vector> #define INF 999999 using namespace std; bool prime[1000000]={0}; int main(){ prime[1]=1; for(int i=2;i*i<=1000000;i++){ if(prime[i]==0){ for(int j=i;j<1000000;j+=i){ prime[j]=1; ...
CPP
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
#include <cmath> #include <iostream> #include <vector> typedef std::vector <int> vi; vi PRIMES; vi prime(int n){ vi s,p; int i,j,x,h; for (i=1;i<=n;i+=2) s.push_back(i); h=s.size(); for (i=1;i<=(int)pow(n,0.5);i++) if (x=s[i]) for (j=i+x;j<h;j+=x) s[j]=0; s[0]=2; for (i=0;i<h;i++) if(s[i]!=0)...
CPP
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
# coding=utf-8 ### ### for atcorder program ### import sys import math # math class class mymath: ### pi pi = 3.14159265358979323846264338 ### Prime Number def pnum_eratosthenes(self, n): ptable = [0 for i in range(n+1)] plist = [] for i in range(2, n+1): if ptab...
PYTHON3
p00053 Sum of Prime Numbers
Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ...
7
0
#include <iostream> #include <algorithm> #include <vector> #include <cmath> using namespace std; int main(){ int a[120000]={0},b,n,sum,cunt; for(int i=2;i<120000;i++) a[i]=1; b=sqrt(120000); for(int i=2;i<=b;i++){ if(a[i]==1){ for(int j=2*i;j<120000;j+=i) a[j]=0; } } while(1){...
CPP