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
# AOJ 0053: Sum of Prime Numbers # Python3 2018.6.15 bal4u MAX = 104729 # 10000th prime SQRT = 323 # sqrt(MAX) prime = [True for i in range(MAX+2)] def sieve(): for i in range(2, MAX, 2): prime[i] = False for i in range(3, SQRT, 2): if prime[i] is True: for j in range(i*i, MAX, i): prime[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
#include <cmath> #include <iostream> #include <vector> typedef std::vector <int> vi; vi P; vi f(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 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
#include <iostream> #include <algorithm> #include <vector> using namespace std; typedef long long lli; const int MAXP = 200000; bool isP[MAXP]; vector<lli> Prime; int main() { fill(isP, isP+MAXP, true); isP[0] = isP[1] = false; for(int i = 2; i < MAXP; ++i) { if(!isP[i]) continue; 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
# Aizu Problem 0053: Sum of Prime Numbers # import sys, math, os, bisect # read input: PYDEV = os.environ.get('PYDEV') if PYDEV=="True": sys.stdin = open("sample-input.txt", "rt") def primes2(n): """ Input n>=6, Returns a list of primes, 2 <= p < n """ n, correction = n-n%6+6, 2-(n%6>1) sieve = [True...
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.*; import java.io.*; public class Main { public static boolean[] sieve (int n) { boolean[] isPrime = new boolean[n]; Arrays.fill(isPrime, true); int lim = (int)Math.sqrt(n); for (int i = 4; i < isPrime.length; i += 2) isPrime[i] = false; for (int i = 3; i <= lim; i += 2) { ...
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 <cmath> using namespace std; int main(){ int n, prime[10000], cnt = 1; prime[0] = 2; for (int i = 3; cnt < 10000; i += 2){ int k = 0; for (int j = 3; j <= sqrt(i); j++) { if (i % j == 0){ k = 1; break; } } if (!k) { prime[cnt] = prime[cnt - 1] + i; cnt++; }...
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<algorithm> #include<cmath> using namespace std; int main (){ int arr[1000000]; int N=1000000; for(int i = 0; i < N; i++){ arr[i] = 1; } for(int i = 2; i < sqrt(N); i++){ if(arr[i]){ for(int j = 0; i * (j + 2) < N; j++){ arr[i *(j + 2)] = 0; } } } 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.util.ArrayList; import java.util.Scanner; //import java.io.*; //import java.util.Arrays; public class Main { public static void main(String[] args) throws java.io.IOException { Scanner scan = new Scanner(System.in); //InputStreamReader is = new InputStreamReader(System.in); //BufferedReader br = new ...
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 def prime(m): N=range(1,m+2,2) r=int(m**.5) 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) N[0]=2 return filter(None,N) PRIMES=prime(105000) for n in sys.stdin: n=int(n) if n==0: break pr...
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; bool ar[110000]={true}; int prime(int x){ int sump=0; int i=110000; for(int a=0;a<i;a++){ar[a]=true;} for(int b=2;b*b<=i;b++){ if(ar[b]){ for(int c=b*b;c<=i;c+=b){ ar[c]=false; } } } int ca=0; for(int d=2;d<=i;d++){ if(ar[d]){ sump+=d; ...
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.Arrays; import java.util.Scanner; public class Main{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); boolean index[]=new boolean[1000000]; Arrays.fill(index, true); index[0]=false; index[1]=false; for(int i=0;i<index.length;i++){ if(index[i]){ for(int j...
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.Arrays; import java.util.Scanner; public class Main { static boolean[] isPrime = new boolean[1000000]; static int[] a; static int[] sum; static{ Arrays.fill(isPrime, true); isPrime[0]=isPrime[1]=false; int count=0; int[] b = new int[100000]; 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 math prime = [0 for i in range(11000)] k = 0 r = 105000 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
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; public class Main { private static ArrayList<Integer> primeNumberList = new ArrayList<>(); public static void main(String[] args) throws NumberFormatException, IOException { BufferedReade...
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> 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
def prime(m): N=range(1,m+2,2) r=int(m**.5) 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) N[0]=2 return filter(None,N) PRIMES=prime(105000) while 1: n=input() if n==0: break print sum(PRIMES[: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 <iostream> #include <vector> using namespace std; bool isprime[1000001]; int main(){ vector<int> v; // init for(int i = 0 ; i <= 1000000 ; i++) isprime[i] = true; isprime[0] = isprime[1] = false; // eratosuteneru for(int i = 2 ; i*i <= 1000000 ; i++){ if( isprime[i] ){ for(int j = i*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<cstdio> #include<iostream> #include<string> #define NMAX (10000+10) #define YES 0 #define NO 1 using namespace std; int main(void){ int huriko[NMAX*20]={YES}; int cnt=0; long long primenum[NMAX]; huriko[0]=NO,huriko[1]=NO; primenum[0]=0; for(int i=2;cnt<NMAX-5;i++){ if(huriko[i]==YES){ cnt++; ...
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 primes(n): is_prime = [True] * (n + 1) is_prime[0] = False is_prime[1] = False for i in range(2, int(n**0.5) + 1): if not is_prime[i]: continue for j in range(i * 2, n + 1, i): is_prime[j] = False return [i for i in range(n + 1) if is_prime[i]] if __name...
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
is_prime = [1] * 200000 primes = [] for i in range(2,200000): if is_prime [i] == False: continue primes.append(i) for j in range(i * 2,200000,i): is_prime [j] = False while True: N = int(input()) if N == 0: break print(sum(primes [: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
import java.util.Scanner; public class Main { public static final int MAX = 200000; public static boolean[] isPrime = new boolean[MAX + 1]; public static void main(String[] args) { Scanner sc = new Scanner(System.in); eratos(); int n = sc.nextInt(); while (n != 0) { int sum = 0, count = 0; for...
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 sieve(n): num = [True] * n num[0] = num[1] = False for i in range(2,int(n**0.5)+1): if num[i]: for j in range(i**2, n, i): num[j] = False return [i for i in range(2, n) if num[i]] prime = sieve(110000) while True: n = int(input()) if n == 0: break print(sum(p...
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(){ int prime[10001],p = 3,psum[10001],n; prime[1] = 2,prime[2] = 3; for(int i=5;p < 10001;i++){ int f = 0; for(int j=1;prime[j]*prime[j] <= i;j++) if(i % prime[j] == 0) {f = 1;break;} if(!f) prime[p++] = i; } psum[1] = 2; ...
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 <algorithm> #include <vector> using namespace std; vector<int> prime; bool isPrime[1000001]; void erats(){ fill(isPrime,isPrime+1000001,true); isPrime[0]=false; isPrime[1]=false; for(int i = 2; i < 1000000; i++){ if(isPrime[i]){ prime.push_back(i); for(int j = i*2; j < 100000...
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.util.stream.*; import java.io.*; import java.math.*; public class Main { static void solve (FastScanner in, PrintWriter out, Methods ms) { ArrayList<Integer> primeList = getPrimeList(ms); while (true) { int n = in.nextInt(); if (n == 0) return; long sum = 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
import java.io.*; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.NoSuchElementException; import java.util.Scanner; public class Main { static ArrayList<Integer> listX = new ArrayList<Integer>(); public stati...
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> #define N 110000 using namespace std; int main(){ bool num[N] ; for(int i =0;i<N;i++) num[i] = true; num[0] = false; num[1] = false; for(int i=2;i*i<N;i++){ if(num[i] == true){ for(int k = i * 2;k<N;k +=i) num[k] = false; } } int n; while(1){ cin >> n; if(n == 0){ 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
#!/usr/bin/env python # -*- coding: utf-8 -*- import sys def make_prime_list(lim): lst = [True for i in xrange(lim + 1)] prime_list = [] num = 2 while num ** 2 <= lim: for i in xrange(num * 2, lim + 1, num): lst[i] = False num += 1 while not lst[num]: nu...
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
#!/usr/bin/env python # -*- coding: utf-8 -*- from __future__ import (division, absolute_import, print_function, unicode_literals) from sys import stdin def enum_prime(limit): L = list(range(2, limit + 1)) P = [] while L[0] ** 2 < limit: P.append(L[0]) L = [i for i 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 <algorithm> #include <string> #include <vector> #include <set> #include <map> using namespace std; int isprime(int n) { int i=3; while(i*i<=n){ if(n%i==0) return false; i+=2; } return true; } int ans(int n) { int i=1; int a=2; int k=3; while...
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<vector> using namespace std; int n; vector<int> p; int sosu[500000]; int main(){ sosu[1]=1; for(int i=2;i<400000;i++){ if(sosu[i]==1) continue; for(int j=i*2;j<400000;j+=i) sosu[j]=1; } for(int i=2;i<400000;i++){ if(!sosu[i]) p.push_back(i); } while(1){ 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
isPrime = [True] * 200001 sum = 0 sumPrime = [sum] def calcPrime(): global sum isPrime[0] = isPrime[1] = False for i in range(len(isPrime)): if(isPrime[i]): sum += i sumPrime.append(sum) for j in range(2 * i, len(isPrime), i): isPrime[j] = False ...
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
from itertools import * n=range(104730);a=list(n) for i in range(2,321):a[i*2::i]=[0]*len(a[i*2::i]) p=list(compress(n,a)) for e in iter(input,'0'):print(sum(p[:int(e)+1])-1)
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> #include<algorithm> using namespace std; bool p[500000]; int s[100000]; void set() { fill(p,p+500000,true); p[0]=false; p[1]=false; for(int i=2;i<500000;i++) { for(int j=2;j*i<500000;j++) { p[i*j]=false; } } int count=0; for(int i=0;i<500000;i++) { if(p[i]) { s[count]=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> using namespace std; bool p[1000000]; int main() { for (int i = 2; i < 1000000; i++){ p[i] = true; } for (int i = 2; i * i < 1000000; i++){ if (p[i]){ for (int j = i * 2; j < 1000000; j += i){ p[j] = false; } } } int n; while (cin >> n, n){ int c = 0; long long 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
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)) 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
import java.io.*; class Main { private static final int M = 104730; public static void main (String args[]) { InputStreamReader isr = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(isr); String buf; int list[] = new int[M+1]; for (int i=2;i<=M;i++) list[i] = 0; 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
#include<iostream> using namespace std; bool isPrime(int n){ if(n<=1 || n!=2&&(n&1)==0)return false; for(int i=3;i*i<=n;i+=2) if(n%i==0)return false; return true; } int main(){ int a[10001]; int n,m=1; a[0]=0;a[1]=2; for(int i=3;m<10000;i+=2){ if(isPrime(i)){ a[m+1]=i+a[m]; m++; } } while(cin>>n&&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 <stdio.h> #include <stdlib.h> #include <math.h> #define MAX 1000000 int main(){ bool p[MAX+1]; int n, sum; p[0] = false; p[1] = false; for(int i=2 ; i<=MAX ; i++){ p[i] = true; } for(int i=2 ; i<=sqrt(MAX)+1 ; i++){ if(p[i]==1){ for(int j=i*2; j<=MAX; j=j+i){ p[j] = false; } } } w...
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.ArrayList; public class Main { private static ArrayList<Integer> primeNumberList = new ArrayList<>(); public static void main(String[] args) throws NumberFormatException, IOException { BufferedReade...
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; bool p[1000000]; int main() { cin.tie(0); ios::sync_with_stdio(false); for (int i = 2; i < 1000000; i++){ p[i] = true; } for (int i = 2; i * i < 1000000; i++){ if (p[i]){ for (int j = 2 * i; j < 1000000; j += i){ p[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
import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String arg[]) { Scanner sc = new Scanner(System.in); while(sc.hasNext()) { int n = sc.nextInt(); if(n==0) return; int ans =0; boolean a[] = new boolean[1000001]; Arrays.fill(a, true); a[0]=a[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
p = [True] * (105000) p[0] = p[1] = False for i in range(2, len(p)): if p[i]: for j in range(i * 2, len(p), i): p[j] = False p = [i for i in range(len(p)) if p[i]] while True: n = int(raw_input()) if n == 0: break print sum(p[: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 <iostream> #include <vector> using namespace std; bool sosu[200000] = {false}; long long int ans[200000] = {0}; int main() { vector<long long int> num; for ( long long int i = 2; i < 200000; i++ ) { ans[i] = ans[i-1]; if ( sosu[i] == false ) { ans[i] += i; num.push_back(i); fo...
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 flag[10000001]; int main(){ int n=0,ans=0,co=0; for(int i=0;i <= 1000000;i++){ if(i<=1)flag[i]=false; else flag[i]=true; } for(int i=2;i <= 1001 ;i++){ if(flag[i]==true){ for(int j=i*2 ; j<=1000000 ; j=j+i){ flag[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 <stdio.h> int main(){ int n,now=1,a[10000]; bool prime[1000000]; a[0]=2; for(int i=3;i<1000000;i+=2){ prime[i]=true; } for(int i=3;now<10000;i+=2){ if(prime[i]){ a[now]=i+a[now-1]; now++; if((long long)i*i<1000000){ for(int...
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(1000000,true); vector<int> p; for(int i = 2; i < 1000000; i++)if(prime[i]){ p.push_back(i); for(int j = 2; i*j < 1000000; j++)prime[i*j] = false; } int n; while(cin >> n,n){ int 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
import sys def prime(m): N=range(1,m+2,2) r=int(m**.5) 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) N[0]=2 return filter(None,N) PRIMES=prime(105000) while 1: n=input() if n==0: break print sum(PR...
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> #define MAX 1000000 bool prime[MAX] = {true}; int p[10000] = {0}; void eratos(void); int main(void) { eratos(); int n, sum; while (scanf("%d", &n)){ if (n == 0) break; sum = 0; for (int i = 0; i < n; i++){ sum += p[i]; // printf("p[i] : %d\n", p[i]); } 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
import sys n=15*10**4 p=[True]*n p[0],p[1]=False,False for i in xrange(2,int(n**0.5)+1): if p[i]==True: for j in xrange(i**2,n,i): p[j]=False s=[i for i in xrange(n) if p[i]] while True: n=input() if n==0:break print sum(s[0: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 <iostream> #include <algorithm> #include <cassert> #include <cctype> #include <cstdio> #include <math.h> #include <map> #include <queue> #include <string> using namespace std; int prime[1000000],n; bool isprime[1000001]; int sieve(int n){ int p=0; for(int i=0;i<=n;i++)isprime[i]=true; isprime[0]=isprime[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.lang.*; import java.math.*; public class Main { Scanner sc = new Scanner(System.in); void run(){ boolean[] np = new boolean[500001]; np[0] = np[1] = true; for(int i=0; i< 500001;i++){ if(np[i]) continue; for(int j = i*2; j < 500001; j += i){ np[j] = 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
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.Scanner; class Main { static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); static Scanner sc = new Scanner(new InputStreamReader(System.in)); public ...
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 = 104729 a = [True] * n a[0] = False for i in range(2,n): if(a[i-1]): for j in range(i**2-1, n, i): a[j] = False a = [i[0]+1 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<iostream> #include<vector> #define MAX 999999 bool prime[MAX]; using namespace std; int main(void){ int n ; vector<int> dp(0,0); //isPrime(); fill(prime,prime+MAX,true); int cnt = 0; prime[0]=prime[1]=false; for(int i = 2 ; i < MAX ; i ++){ if(prime[i]){ cnt += i; for(int 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
//0053 #include<cstdio> #include<algorithm> int main(void) { const int N = 104729+1; //1000”Ô–Ú‚Ì‘f”‚Í104729 bool isPrime[N]; std::fill(isPrime, isPrime+N, true); isPrime[0] = isPrime[1] = false; int i, j; for(i = 2; i*i <= N; i++) { if(isPrime[i]) { for(j = i*2; j < N; j+=i) { isPrime[j] = fals...
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 sc=new Scanner(System.in); while(true){ int n=sc.nextInt(); if(n==0){ break; } if(n==1){ System.out.println(2); break; } int count=1; int sum=2; for(int i=3;count<n;i+=2){ boolean f...
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 p[1000000]; int main() { int i,j,k=1; vector<int> v(10000); v[0] = 2; for(i=3;i<1000000;i+=2){ if(p[i] == 0){ v[k] = i + v[k-1]; k++; if(k >= 10000) break; for(j=i*2;j<1000000;j+=i){ p[j] = 1; } } } while(c...
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 { static boolean prime[] = new boolean[200000]; static int[] result = new int[10002]; static void Do(int k){ int sum=0; for(int i=1;i<=k;i++){ sum+=P(i); } } static int P(int n){ int cnt=0; for(int i=0;i<prime.length;i++){ if(prime[i]){ cnt++; if(cnt==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.math.BigInteger; import java.util.*; import static java.util.Arrays.*; import static java.lang.Math.*; // AOJ 0053 public class Main { static Scanner sc = new Scanner(System.in); public static void main(String[] args) { sieve(1000000); while (true) { int n = sc.nextInt(); if (n == 0) break; ...
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,time n = 104730 a = [True] * n a[0] = a[1] = False for i in range(2,n): if(a[i]): for j in range(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<cstdio> #include<cmath> using namespace std; int dp[10010]; int prime(int n) { int i, j,d; if (n == 1) { return dp[1] = 2; }; d = dp[n - 1]; for (i = d+1;; i++) { for (j = 2;; j++) { if (i%j == 0)break; if (j == (int)sqrt(i)+1) { return dp[n] = i; } } } } int main() { int n, i; long long 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> using namespace std; int prime[10000]; int ptr = 0; bool isPrime(int p) { if (p <= 1)return false; for (int i = 2; i * i <= p; i++) { if (p % i == 0)return false; } return true; } void setPrime() { for (int i = 2;;i++) { if (ptr >= 10000)break; if (isPrime(i))prime[ptr++] = i; } } int ...
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> #define N 1000000 using namespace std; int main(){ int n; int arr[N]; for(int i=0;i<N;i++){ arr[i]=1; } for(int i=2;i<sqrt(N);i++){ if(arr[i]){ for(int j=0;i*(j+2)<N;j++){ arr[i*(j+2)]=0; } } } while(true){ cin >> n; if(n==0){ break; } int cnt=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 { //‘f”‚©‚Ç‚¤‚©‚ð”»•Ê‚·‚éŠÖ” private boolean isPrime(int n){ for(int i=2; i * i <= n; i++){ if(n % i == 0){ return false; } } return true; } public void doIt(){ Scanner sc = new Scanner(System.in); //ƒGƒ‰ƒgƒXƒeƒlƒX‚̂ӂ邢 final int MAX = 999999; b...
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 scan = new Scanner(System.in); int[] v = new int[649900]; for(int i = 0;i < 649900;i++){ v[i] = 1; } int p = 3; while(true){ if(p*p > 1299800){ break; }else{ if(v[(p-1)/2] == 0){ p += 2; ...
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; int main() { int prime[120001],num,cou=0,ans=0; for(int i=2;i<=120000;i++)prime[i]=0; for(int i=2;i<=(int)sqrt(120000);i++){ for(int j=2;j*i<=120000;j++)prime[i*j]=1; } while(cin>>num&&num!=0){ for(int i=2;cou<num;i++){ if(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> int p[1<<17],n,s,i; int main(){p[1]=1;for(i=2;i*i<1<<17;i++)if(!p[i])for(s=2;i*s<1<<17;s++)p[i*s]++;for(;std::cin>>n,n;){for(i=2,s=0;n;i++)if(!p[i])s+=i,n--;std::cout<<s<<"\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> #include<cstring> int sumPrime[10000]; void makePrime(){ const int max=1000000; bool sieve[max]; int k=0; memset(sieve,true,sizeof(sieve)); for(int i=0;i<max&&k<10000;++i){ if(sieve[i]){ sumPrime[k]=i+2+(k>0?sumPrime[k-1]:0); ++k; for(int j=i*2+2;j<max;j+=i+2){ sieve[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
a=[True]*104743 p=[] for i in range(2,int(104743**0.5)+1): if a[i]: for j in range(i*i,104743,i):a[j]=False for i in range(2,104730): if a[i]:p.append(i) while 1: n=int(input()) if n==0:break print(sum(p[: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
import java.util.ArrayList; import java.util.Arrays; import java.util.Calendar; import java.util.Scanner; public class Main { Scanner sc = new Scanner(System.in); public static void main(String[] args) { new Main().AOJ0053(); } void AOJ0053(){ ArrayList<Integer> primes = primeTable(1000000); while(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
import java.util.Scanner; class Main { public static void main(String[] args) { int[] prime = new int[10000000]; for(int i=0;i<10000000;i++) { prime[i]=0; } for(int i=2; i<10000000; i++) { if(prime[i]==1) { continue; } prime[i]=2; int j=i+i; while(j<1000000...
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 p[104730]={0},n,s,i,j; int main(){ p[1]=1; for(i=2;i*i<104730;i++) if(!p[i]) for(j=2;i*j<104730;j++) p[i*j]=1; while(cin>>n,n) { for(i=2,s=0;n;i++) if(!p[i]) s+=i,n--; cout<<s<<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
#include <iostream> using namespace std; int isprime(int n){ if(n<2)return 0; if(n==2)return 1; if(n%2==0)return 0; for(int i=3;i*i<=n;i+=2){ if(n%i==0)return 0; } return 1; } int main(){ int a,n[10001]={0},k; k=0; for(int i=1;k<=10000;i++){ if(isprime(i)){ k++; n[k]=n[k-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
def sieve(n): primes = [True] * n primes[0] = primes[1] = False for i in xrange(2, int(n ** 0.5) + 1): if primes[i]: for j in xrange(i * i, n, i): primes[j] = False return [i for i in xrange(n) if primes[i]] prime_list = sieve(200000) while 1: a = input() if ...
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> #define x 200000 using namespace std; int main(){ int p[x+1]; bool q[x+1]; for(int i=2;i<=x;i++) q[i] = true; for(int i=2;i<=x;i++){ if(not q[i]) continue; for(int j=2;j<=x/i;j++) q[i*j] = false; } int c = 0; for(int i=2;i<=x;i++) if(q[i]) p[c++] = i; int n; while(1){ cin >> n; 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> #define N 104730 using namespace std; int main(){ int n; int m=0; bool ip[N]; int p[10000]; for(int i=0;i<N;i++) ip[i]=true; ip[0]=ip[1]=false; for(int i=2;i<N;i++){ if(ip[i]){ p[m++]=i; for(int j=2*i;j<N;j+=i) ip[j]=false; } } while(1){ int a=0; cin>>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> using namespace std; bool p[200000]; void erato(){ fill(p, p+200000, true); p[0] = p[1] = false; for(int i=0; i*i < 200000; i++){ if(!p[i]) continue; for(int j= i+i; j < 200000; j += i){ p[j] = false; } } } int main(){ erato(); int ans, num, input; while(cin >> input, input){ a...
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=range(104730);a=list(n) for i in range(2,320):a[i*2::i]=[0]*len(a[i*2::i]) p=list(compress(n,a)) for e in iter(input,'0'):print(sum(p[:int(e)+1])-1)
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<string> #include<vector> #include<cstdio> #include<sstream> #include<algorithm> #include<cmath> #include<map> #include<functional> using namespace std; int stoi(string x){stringstream ss;ss<<x;int tmp;ss>>tmp;return tmp;} string itos(int x){stringstream ss;ss<<x;return ss.str();} bool is(int...
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 accumulate, chain ub = 105000 primes = {2, 3} | {m for n in (5, 7) for m in range(n, ub, 6)} du = primes.difference_update for n in chain(range(5, ub, 6), range(7, ub, 6)): if n in primes: du(range(n*3, ub, n*2)) cumsum = tuple(accumulate(primes)) while True: n = int(input()) ...
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 sosu[110000] = { false }; for (int i = 2; i <= sizeof(sosu) / sizeof(bool); ++i) { if (sosu[i] == false) { for (int k = i * 2; k <= sizeof(sosu) / sizeof(bool); k+=i) { sosu[k] = true; } } } int answer; int time; while (1) { cin >> time; ...
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; #define MAX_LIST 105000 int main(){ bool prime[MAX_LIST]; for(int i=0;i<MAX_LIST;i++){ prime[i]=1; } prime[0]=prime[1]=0; for(int i=0;i*i<MAX_LIST;i++){ if(prime[i]==1){ for(int j=i*2;j<MAX_LIST;j=j+i){ prime[j]=0; } } } int primelist[10000]; int j=0; for(int i=0;i<MAX_LIST;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 <bitset> using namespace std; #define MAX 1000001 bitset<MAX> bs; int n; long int s[10001] = { 0 }; int main(){ int it = 1; for (int i = 2; i < MAX; i++) { if (!bs[i]) { for (int j = i + i; j < MAX; j += i) { bs.set(j); } s[it] = s[it - 1] + i; it++; if (it > 10000) ...
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 <cmath> #include <algorithm> #define NUM 120000 int main(){ int table[NUM],limit; for(int i=0; i < NUM;i++)table[i] = 1; table[0] = 0; table[1] = 0; limit = sqrt(NUM); for(int i=2;i<=limit;i++){ if(table[i] == 1){ for(int k=2*i;k < NUM; k += i){ table[k] = 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> using namespace std; int main(void){ bool prime[1000000]; for(int i=0;i<=1000000;i++) prime[i]=true; prime[0]=prime[1]=false; for(int i=2;i<=1000000;i++) if(prime[i]) for(int j=2*i;j<=1000000;j+=i) prime[j]=false; int sum[10001]={0}; int index=1; for(int i=0;i<=1000000;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<bits/stdc++.h> using namespace std; int num[500000]={0}; int main(){ for(int i=2;i<sqrt(500000);i++){ for(int j=i;j<500000;j+=i){ if(num[j]==0 && j!=i){ num[j]=1; } } } while(1){ int n; cin>>n; if(n==0) break; int cnt=0; long long sum=0; for(int i=2;i<500000;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> #include <math.h> int prime[200000]; void Eratos(void); int main(void){ int n; int p[10000]; int num = 0; int ans; Eratos(); for(int i=0; num < 10000; i++){ if(prime[i] == 1){ p[num] = i; num++; } } while(1){ ans = 0; scanf("%d", &n); if(n == 0) break; for(int i=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
#include<iostream> using namespace std; int main(){ int p[10000]; int j=3; int a; bool c; p[0]=2; for(int i=1;i<10000;i++){ for(;;j++){ c=true; for(int k=2;k*k<=j;k++){ a=j; a%=k; if(a==0){c=false; break;}} if(c){ p[i]=p[i-1]+j; j++; break;} }} int n; while(cin>>n){ if(n==0)break; cout<<p[n-1]<<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
import sys def prime(m): N=range(1,m+2,2) r=int(m**.5) 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) N[0]=2 return filter(None,N) PRIMES=prime(105000) while 1: n = input() if n==0: break s = sum(PR...
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<stdio.h> int main(void){ int i,j,k; int prime[10000],sum[10000]; int n; i = 1; k = 3; prime[0] = sum[0] = 2; while(i<10000){ n = 1; for(j=0;prime[j]*prime[j]<=k;j++){ if(!(k%prime[j])){ n = 0; break; } } if(n){ prime[i] = k; sum[i] = sum[i-1]+k; 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.ArrayList; import java.util.Scanner; public class Main { public static void main(String[] args) { ArrayList<Integer> primes = prime(104740); Scanner sc = new Scanner(System.in); while (sc.hasNext()) { int n = sc.nextInt(); if (n == 0) { break; } long sum = 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
#include<bits/stdc++.h> using namespace std; int main() { long long int prime[120001],num,cou=0,ans=0; for(int i=2;i<=120000;i++)prime[i]=0; for(int i=2;i<=(int)sqrt(120000);i++){ for(int j=2;j*i<=120000;j++)prime[i*j]=1; } while(cin>>num&&num!=0){ for(int i=2;cou<num;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 math M = 104729 lst = list(range(M+1)) for i in range(0, M+1, 2): lst[i] = 0 lst[1] = 0 lst[2] = 2 for i in range(3, math.ceil(math.sqrt(M+1)), 2): if lst[i]: for j in range(i**2, M+1, i): lst[j] = 0 anslst = [i for i in lst if i != 0] while True: n = int(input()) if 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> using namespace std; #define MAX 1000000 vector<int> prime; bool is_prime[MAX+1]; void Sieve() { for(int i=0; i<=MAX; i++) { is_prime[i] = true; } is_prime[0] = is_prime[1] = false; for(int i=2; i<=MAX; i++) { if(is_prime[i]) { prime.push_back( i )...
CPP
p00183 Black-and-White
Consider a tic-tac-toe on a 3x3 board. Tic-tac-toe is a two-player battle game. Decide the first attack and the second attack, one hits Kuroishi and one hits Shiraishi. The winner is the person who puts stones one by one on the board alternately and arranges three of his own stones first in either the vertical, horizon...
7
0
#include <iostream> #include <string> using namespace std; int main(){ char d[9]; string m[8]={"012","345","678","036","147","258","048","246"}; int f; while(cin>>d[0],d[0]!='0'){ for(int i=1;i<=8;i++)cin>>d[i]; f=1; for(int i=0;i<8;i++){ if(d[m[i][0]-'0']==d[m[i][1]-'0']&&d[m[i][1]-'0']==d[m[i][2]-'0']&&...
CPP
p00183 Black-and-White
Consider a tic-tac-toe on a 3x3 board. Tic-tac-toe is a two-player battle game. Decide the first attack and the second attack, one hits Kuroishi and one hits Shiraishi. The winner is the person who puts stones one by one on the board alternately and arranges three of his own stones first in either the vertical, horizon...
7
0
#include<iostream> #include<string> using namespace std; int main(){ while(true){ string brd[3]; bool bWin=false; bool wWin=false; for(int i = 0; i < 3; ++i){ cin >> brd[i]; if( brd[i] == "0") return 0; } // row for(int i = 0; i < 3; ++i){ int b=0,w=0; for(int...
CPP
p00183 Black-and-White
Consider a tic-tac-toe on a 3x3 board. Tic-tac-toe is a two-player battle game. Decide the first attack and the second attack, one hits Kuroishi and one hits Shiraishi. The winner is the person who puts stones one by one on the board alternately and arranges three of his own stones first in either the vertical, horizon...
7
0
#include <iostream> #include <cstdio> using namespace std; string f[3]; int main() { while (cin>>f[0]) { if (f[0]=="0") break; for (int i=1; i<3; i++) cin>>f[i]; char res='+'; for (int i=0; i<3; i++) { if (f[0][i]==f[1][i]&&f[1][i]==f[2][i]) { if (f[0][i]!...
CPP
p00183 Black-and-White
Consider a tic-tac-toe on a 3x3 board. Tic-tac-toe is a two-player battle game. Decide the first attack and the second attack, one hits Kuroishi and one hits Shiraishi. The winner is the person who puts stones one by one on the board alternately and arranges three of his own stones first in either the vertical, horizon...
7
0
#include<iostream> #include<algorithm> #include<climits> #include<cmath> #include<cstdio> #include<cstdlib> #include<ctime> #include<string> #include<cstring> #include<vector> #include<stack> #include<queue> #include<set> #include<map> #include<bitset> using namespace std; typedef long long ll; typedef unsigned long ...
CPP
p00183 Black-and-White
Consider a tic-tac-toe on a 3x3 board. Tic-tac-toe is a two-player battle game. Decide the first attack and the second attack, one hits Kuroishi and one hits Shiraishi. The winner is the person who puts stones one by one on the board alternately and arranges three of his own stones first in either the vertical, horizon...
7
0
chk = [ (1,2,3), (4,5,6), (7,8,9), (1,4,7), (2,5,8), (3,6,9), (1,5,9), (3,5,7) ] while True: s = "0" s += raw_input() if s[1]=='0': break s += raw_input()+raw_input() judge = "NA" for ch in chk: if s[ch[0]]==s[ch[1]]==s[ch[2]]: if s...
PYTHON