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
p03962 AtCoder Beginner Contest 046 - AtCoDeer and Paint Cans
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive. Since he is forgetful, he migh...
6
0
import java.util.HashSet; import java.util.Scanner; public class Main { public static void main(String[] args){ Scanner scanner = new Scanner(System.in); HashSet<Integer> hs = new HashSet<Integer>(); for(int i = 0 ;i < 3;i++)hs.add(scanner.nextInt()); System.out.println(hs.size()); scanner.close...
JAVA
p03962 AtCoder Beginner Contest 046 - AtCoDeer and Paint Cans
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive. Since he is forgetful, he migh...
6
0
c = list(map(int,input().split())) print(len(set(c)))
PYTHON3
p03962 AtCoder Beginner Contest 046 - AtCoDeer and Paint Cans
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive. Since he is forgetful, he migh...
6
0
#include<bits/stdc++.h> using namespace std; int main() { int a,b,c; cin>>a>>b>>c; set<int>s; s.insert(a); s.insert(b); s.insert(c); cout<<s.size()<<endl; }
CPP
p03962 AtCoder Beginner Contest 046 - AtCoDeer and Paint Cans
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive. Since he is forgetful, he migh...
6
0
#include <bits/stdc++.h> using namespace std; int main () { set<int> s; int k; while (cin >> k) { s.insert(k); } cout << s.size() << endl; }
CPP
p03962 AtCoder Beginner Contest 046 - AtCoDeer and Paint Cans
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive. Since he is forgetful, he migh...
6
0
n = set(map(int,input().split())) print(len(n))
PYTHON3
p03962 AtCoder Beginner Contest 046 - AtCoDeer and Paint Cans
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive. Since he is forgetful, he migh...
6
0
import java.util.HashSet; import java.util.Scanner; import java.util.Set; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); Set<Integer> set = new HashSet<>(); set.add(sc.nextInt()); set.add(sc.nextInt()); set.add(sc.nextInt...
JAVA
p03962 AtCoder Beginner Contest 046 - AtCoDeer and Paint Cans
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive. Since he is forgetful, he migh...
6
0
#include<bits/stdc++.h> using namespace std; int main() { int a,b,c; cin>>a>>b>>c; set<int>s; s.insert(a); s.insert(b); s.insert(c); cout<<s.size(); }
CPP
p03962 AtCoder Beginner Contest 046 - AtCoDeer and Paint Cans
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive. Since he is forgetful, he migh...
6
0
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int a = sc.nextInt(); int b = sc.nextInt(); int c = sc.nextInt(); int cnt = 0; if(a == b && b == c) { cnt = 1; } else if(a != b && b != c && a != c) { cnt = 3; } else { ...
JAVA
p03962 AtCoder Beginner Contest 046 - AtCoDeer and Paint Cans
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive. Since he is forgetful, he migh...
6
0
import java.util.HashSet; import java.util.Scanner; import java.util.Set; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); Set<Integer> set = new HashSet<Integer>(); for(int i = 0; i < 3; i++) { set.add(sc.nextInt()); } sc.close(); System.out.println(set...
JAVA
p03962 AtCoder Beginner Contest 046 - AtCoDeer and Paint Cans
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive. Since he is forgetful, he migh...
6
0
import sys abc = sys.stdin.readline().split() abc_arr = [] for x in abc: if x not in abc_arr: abc_arr.append(x) print len(abc_arr)
PYTHON
p03962 AtCoder Beginner Contest 046 - AtCoDeer and Paint Cans
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive. Since he is forgetful, he migh...
6
0
import java.util.*; public class Main { public static void main(String[] args) { // TODO Auto-generated method stub Scanner reader=new Scanner(System.in); int a= reader.nextInt(); int b= reader.nextInt(); int c= reader.nextInt(); Set<Integer>s=new HashSet<Integer>(); s.add(a); s.add(b); s.add(c); ...
JAVA
p03962 AtCoder Beginner Contest 046 - AtCoDeer and Paint Cans
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive. Since he is forgetful, he migh...
6
0
color = input().split() print(len(set(color)))
PYTHON3
p03962 AtCoder Beginner Contest 046 - AtCoDeer and Paint Cans
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive. Since he is forgetful, he migh...
6
0
#include <bits/stdc++.h> using namespace std; //型に気を付けよう int main() { int a,b,c; cin>>a>>b>>c; int cnt=1; if(b!=a)cnt++; if(b!=c&&a!=c)cnt++; cout<<cnt; }
CPP
p03962 AtCoder Beginner Contest 046 - AtCoDeer and Paint Cans
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive. Since he is forgetful, he migh...
6
0
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c; cin>>a>>b>>c; unordered_map<int,int> cnt; cnt[a]++; cnt[b]++; cnt[c]++; cout<<cnt.size(); return 0; }
CPP
p03962 AtCoder Beginner Contest 046 - AtCoDeer and Paint Cans
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive. Since he is forgetful, he migh...
6
0
#include<iostream> using namespace std; int main(){ int a,b,c; cin>>a>>b>>c; int sum = 3; if(a == b)sum--; if(a == c)sum--; else if(b == c)sum--; cout << sum << endl; return 0; }
CPP
p03962 AtCoder Beginner Contest 046 - AtCoDeer and Paint Cans
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive. Since he is forgetful, he migh...
6
0
#include <bits/stdc++.h> using namespace std; int main(){ set<int> S; int x=3; int a; while(x--){ scanf("%d",&a); S.insert(a); } printf("%d\n",S.size()); return 0; }
CPP
p03962 AtCoder Beginner Contest 046 - AtCoDeer and Paint Cans
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive. Since he is forgetful, he migh...
6
0
a=[i for i in input().split()] print(len(set(a)))
PYTHON3
p03962 AtCoder Beginner Contest 046 - AtCoDeer and Paint Cans
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive. Since he is forgetful, he migh...
6
0
#include <iostream> #include <set> using namespace std; int main(void){ set<int> st; for(int i = 0;i < 3;i++){ int a; cin >> a; st.insert(a); } cout << st.size() << endl; }
CPP
p03962 AtCoder Beginner Contest 046 - AtCoDeer and Paint Cans
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive. Since he is forgetful, he migh...
6
0
a=set(list(map(int,input().split()))) print(len(a))
PYTHON3
p03962 AtCoder Beginner Contest 046 - AtCoDeer and Paint Cans
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive. Since he is forgetful, he migh...
6
0
#include <iostream> #include <map> using namespace std; int main(){ map<int, int> m; for(int i = 0; i < 3; i++){ int a; cin >> a; m[a]++; } cout << m.size() << endl; }
CPP
p03962 AtCoder Beginner Contest 046 - AtCoDeer and Paint Cans
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive. Since he is forgetful, he migh...
6
0
#include<stdio.h> #include<algorithm> using namespace std; int main(){ int a,b,c; scanf("%d%d%d",&a,&b,&c); int ret=1; if(a!=b)ret++; if(b!=c&&a!=c)ret++; printf("%d\n",ret); }
CPP
p03962 AtCoder Beginner Contest 046 - AtCoDeer and Paint Cans
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive. Since he is forgetful, he migh...
6
0
#include <bits/stdc++.h> using namespace std; int main(){ int A, B, C; cin>>A>>B>>C; set<int> s; s.insert(A); s.insert(B); s.insert(C); cout<<s.size()<<endl; return 0; }
CPP
p03962 AtCoder Beginner Contest 046 - AtCoDeer and Paint Cans
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive. Since he is forgetful, he migh...
6
0
#include <iostream> #include <set> using namespace std; int main(void){ int x=3; set<int> s; while(x--){ int a; cin >> a; s.insert(a); } cout << s.size() << endl; }
CPP
p03962 AtCoder Beginner Contest 046 - AtCoDeer and Paint Cans
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive. Since he is forgetful, he migh...
6
0
#include<bits/stdc++.h> using namespace std; int main(){ int cnt=0,a,b,c; cin>>a>>b>>c; set<int>s; s.insert(a); s.insert(b); s.insert(c); for(int x:s)cnt++; cout<<cnt; return 0; }
CPP
p03962 AtCoder Beginner Contest 046 - AtCoDeer and Paint Cans
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive. Since he is forgetful, he migh...
6
0
import java.util.ArrayList; import java.util.Scanner; public class Main { public static void main (String[] args) { Scanner scan = new Scanner(System.in); ArrayList<Integer> color = new ArrayList<Integer>(); for(int i=0; i<3; i++) { int cl = scan.nextInt(); if(!color.contains(cl))color.add(cl); } Sys...
JAVA
p03962 AtCoder Beginner Contest 046 - AtCoDeer and Paint Cans
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive. Since he is forgetful, he migh...
6
0
import java.util.*; public class Main { public static void main(String [] args){ Scanner sc = new Scanner(System.in); int a=0,b=0,c=0,num=1; a=sc.nextInt(); b=sc.nextInt(); c=sc.nextInt(); if(a!=b)num++; if(a!=c&&b!=c)num++; System.out.println(num); ...
JAVA
p03962 AtCoder Beginner Contest 046 - AtCoDeer and Paint Cans
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive. Since he is forgetful, he migh...
6
0
#include <bits/stdc++.h> using namespace std; int main(){ set<int> s; int a, b, c; cin >> a >> b >> c; s.insert(a); s.insert(b); s.insert(c); cout << s.size(); return 0; }
CPP
p03962 AtCoder Beginner Contest 046 - AtCoDeer and Paint Cans
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive. Since he is forgetful, he migh...
6
0
import java.util.HashSet; import java.util.Scanner; public class Main{ public static void main(String[] args) { Scanner scanner = new Scanner(System.in); HashSet hs = new HashSet(); hs.add(scanner.nextInt()); hs.add(scanner.nextInt()); hs.add(scanner.nextInt()); System.out.println(hs.size()); scanner...
JAVA
p03962 AtCoder Beginner Contest 046 - AtCoDeer and Paint Cans
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive. Since he is forgetful, he migh...
6
0
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int a = scanner.nextInt(), b = scanner.nextInt(), c = scanner.nextInt(); int count = 0; if(a != b){ count++; } if(b != c){ count++; } if(c != a){ count++; } if...
JAVA
p03962 AtCoder Beginner Contest 046 - AtCoDeer and Paint Cans
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive. Since he is forgetful, he migh...
6
0
#include<iostream> #include<set> using namespace std; int main() { int a, b, c; cin >> a >> b >> c; set<int>st{a, b, c}; cout << st.size() << endl; }
CPP
p03962 AtCoder Beginner Contest 046 - AtCoDeer and Paint Cans
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive. Since he is forgetful, he migh...
6
0
import java.util.Scanner; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int a = sc.nextInt(); int b = sc.nextInt(); int c = sc.nextInt(); if(a == b && b == c){System.out.println(1);} else if(a != b && a != c && b != c){Sys...
JAVA
p03962 AtCoder Beginner Contest 046 - AtCoDeer and Paint Cans
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive. Since he is forgetful, he migh...
6
0
#include <bits/stdc++.h> using namespace std; int main(){ int a,b,c; cin>>a>>b>>c; int count=1; if(b-a!=0)count++; if(c-a!=0 && c-b!=0)count++; cout<<count; }
CPP
p03962 AtCoder Beginner Contest 046 - AtCoDeer and Paint Cans
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive. Since he is forgetful, he migh...
6
0
s = set(input().split()) print(len(s))
PYTHON3
p03962 AtCoder Beginner Contest 046 - AtCoDeer and Paint Cans
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive. Since he is forgetful, he migh...
6
0
print(len(set(input().split())))
PYTHON3
p03962 AtCoder Beginner Contest 046 - AtCoDeer and Paint Cans
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive. Since he is forgetful, he migh...
6
0
#include<bits//stdc++.h> using namespace std; int main(){ set<int> s;int a,b,c;cin >> a >> b >> c; s.insert(a);s.insert(b);s.insert(c); cout << s.size() << endl; }
CPP
p03962 AtCoder Beginner Contest 046 - AtCoDeer and Paint Cans
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive. Since he is forgetful, he migh...
6
0
import java.util.*; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int[] n=new int[3]; int f=3; for(int i=0;i<3;i++){ n[i]=sc.nextInt(); } if(n[0]==n[1]){ f--; if(n[0]==n[2]){ f--; } }else if(n[1]==n[2]){ ...
JAVA
p03962 AtCoder Beginner Contest 046 - AtCoDeer and Paint Cans
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive. Since he is forgetful, he migh...
6
0
abc = set(input().split()) print(len(abc))
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
num = 200000 L = [True] * (num+1) L[0] = False L[1] = False for i in range( 2, int(num**0.5)+ 2 ): if not L[i]: continue for j in range(i*2, num+1, i): L[j] = False p = [ x for x in range(num+1) if L[x] ] while True: n = int(input()) if n == 0: break print(sum(p[0: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.Arrays; import java.util.Scanner; public class Main { static Scanner sc = new Scanner(System.in); public static void main(String[] args) { //?´???°?±??????? boolean[] search = new boolean[10000000]; Arrays.fill(search, true); for(int i = 2; i < 10000000; 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.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n,i,j,sum,count; boolean p[]=new boolean[110000]; Arrays.fill(p, true); for(i=2;i<110000;i++){ if(p[i]){ for(j=2;i*j<110000;j++){ p[i*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> #include <algorithm> #include <vector> using namespace std; vector<int> prime; int ps[10000]; bool judge(int n){ if (n == 2) return true; for (int i = 2; i*i <= n; i++) if (n % i == 0) return false; return true; } void pgen(){ for (int i = 2; prime.size() != 10000; i++) if (judge(i)) 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
import java.util.*; public class Main { void AOJ0053(){ Scanner sc = new Scanner(System.in); int MAX = 10000000; boolean[] list = new boolean[MAX+1]; Arrays.fill(list, true); int count=1; long[] sum = new long[10001]; sum[0]=0; for(int i=2; i<=MAX; i++){ if(list[i]){ sum[count] = sum[count-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
import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Scanner; public class Main{ static List<Integer> primes = findPrimes(104729); private static List<Integer> findPrimes(int n){ boolean[] isPrime = new boolean[n]; Arrays.fill(isPrime, true); isPrime[0] = false; 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
import java.util.ArrayList; import java.util.Arrays; import java.util.Scanner; public class Main { static final int N = 10000; public static void main(String[] args) { new Main().solve(); } void solve(){ Scanner sc = new Scanner(System.in); // メモ化みたいな ArrayList<Long> p = new ArrayList<Long>(); fo...
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.Arrays; import java.util.Scanner; //Sum of Prime Numbers public class Main{ public static void main(String[] args) { boolean[] p = new boolean[104730]; int[] s = new int[10001]; int k=0; s[k++]=0; Arrays.fill(p, true); for(int i=2;i<104730;i++){ if(p[i]){ s[k]=s[k-1]+i; k++; ...
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 { private static int[] calcPrimes(int n) { boolean[] table = new boolean[n + 1]; for (int i = 2; i <= Math.sqrt(n); i++) { if (!table[i]) { for (int j = i + i; j <= n; j += i) { table[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.util.*;class Main{public static void main(String[]z){int i=0,e=2,t=10000;int[]p=new int[t];for(;i<t;i++){for(;f(p,e)<1;e++);p[i]=e++;}for(i=1;i<t;++i)p[i]+=p[i-1];for(Scanner s=new Scanner(System.in);(i=s.nextInt())>0;)System.out.println(p[i-1]);}static int f(int[]p,int n){for(int e:p)if(e>0&&n!=e&&n%e<1)re...
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
//56 #include<iostream> #include<vector> using namespace std; int main(){ vector<int> prime; vector<int> psum(1,0); for(int i=2;prime.size()<10000;i++){ int j; for(j=0;j<prime.size();j++){ if(i%prime[j]==0)break; } if(!(j<prime.size())){ prime.push_back(i); psum.push_back(psum....
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> using namespace std; int main(){ long long int a[1000000] = {0}; a[0] = 1; a[1] = 1; for(int i=2;i*i<=1000000;i++){ if(a[i] == 0){ for(int j=i+i;j<=1000000;j+=i) a[j] = 1; } } int n; while(cin >> n, n){ int ans = 0,t = 0,s = 0; while(t < 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
import java.util.*; class Main{ public static void main(String[] args){ int n; final int MAX_N = 10000; Scanner scan = new Scanner(System.in); ArrayList<Integer> al = new ArrayList<Integer>(); for(int i = 2;al.size() < MAX_N;i++){ boolean b = true; for(int j = 0;j < al.size();j++){ if(i % al.get(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
#include<iostream> using namespace std; bool f(int a) { for(int i=2;i*i<=a;i++)if(a%i<1)return 0; return 1; } int n; int main() { while(cin>>n,n) { int ans=0; for(int i=2;n;i++)if(f(i))n--,ans+=i; cout<<ans<<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
maxnum = 110000 primes = [True]*maxnum primes[0] = primes[1] = False for i in xrange(maxnum): if i >= maxnum**0.5 : break if not primes[i]: continue for j in xrange(i*2,maxnum,i): primes[j] = False p = [ i for i in xrange(maxnum) if primes[i] ] while True: n = int(raw_input()) if n == 0: break ...
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; bool table[105000]; vector<int> primes; int main() { table[2] = true; for (int i = 3; i < 105000; i += 2) table[i] = true; for (int i = 3; i <= 324; i += 2) if (table[i]) for (int j = 3 * i; j < 105000; j += 2 * i) table[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
from math import sqrt, ceil from itertools import accumulate N = 120000 temp = [True]*(N+1) temp[0] = temp[1] = False for i in range(2, ceil(sqrt(N+1))): if temp[i]: temp[i+i::i] = [False]*(len(temp[i+i::i])) cumsum = [i for i in range(N) if temp[i]] cumsum = list(accumulate(cumsum)) 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 <cstdio> using namespace std; int main(){ bool prime[1000000]; int n, p, res; while(true){ scanf("%d", &n); if(n == 0) break; p = 2; res = 0; for(int i = 0; i < 1000000; i++) prime[i] = true; for(int i = 0; i < n; i++){ while(!prime[p]) p++; res += p; for(int j = p; j < 1000000; 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<algorithm> #define MAX 1000001 using namespace std; char prime[MAX]; void furui(int n) { int i,j; prime[0]=prime[1]=1; for(i=2;i*i<=n;i++){ if( prime[i] ) continue; for(j=i*2;j<=n;j+=i){ prime[j]=1; } } } int main(){ int n; int i,j; int 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
#include <iostream> #include <numeric> using namespace std; int main() { bool prime[1000000]; fill(prime, prime + 1000000, true); prime[0] = prime[1] = false; for (int i = 2; i * i < 1000000; i++) { for (int j = 2; j * i < 1000000; j++) { if (!prime[i * j]) continue; prime[i * j] = false; } } int 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 isprime(int n, int k) { if (k * k > n) { return true; } if (n % k == 0){ return false; } return isprime(n, k + 1); } int main() { const int DATASETS = 10000; int n[10000], p[10000], c1 = 0, c2 = 2, c3 = 0; while (c1 < 10000) { if (isprime(c2, 2) == 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<cstdio> using namespace std; int main() { static bool era[1000000]; for(int i=2;i<1000;i++){ if(!era[i])for(int j=i*i;j<1000000;j+=i)era[j]=true; } static int p[10001]; for(int i=2,j=0;j<10001;i++) if(!era[i]) p[j++]=i; static int s[10001]={0,p[0]}; for(int i=1;i<10000;i++) s[i+1]=s[i]+p[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
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.Scanner; public class Main { static ArrayList<Integer> list = new ArrayList<Integer>(); static ArrayList<Integer> listX = new ArrayList<Intege...
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; const unsigned LIMIT = 105000; int main(){ bool table[ LIMIT ] = { false }; table[ 2 ] = true; for ( int i = 3; i < LIMIT; i += 2 ){ table[ i ] = true; } for ( int i = 3; i < LIMIT; i += 2 ){ if ( !table[ i ] ) continue; for ( int j = i + i; j < LIMIT; j += 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 <vector> using namespace std; typedef long long int LLI; int n; bool is_composite[1000000]; LLI imos[1000000]; vector<LLI> primes; int main() { for (int i=2; i<1000000; i++) { if (!is_composite[i]) { primes.push_back(i); for (int j=i+i; j<1000000; j+=i) is_composite[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 <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*i<=n;i++) if (x=s[i]) for (j=x*x/2;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]); return p; } int main(v...
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 isPrime(int n){ for(int i=2;i*i<=n;i++) if(n%i==0) return false; return true; } int main(){ int d[10005]={}; int i=2,k=1; while(k<10005) { while(!isPrime(i)) i++; d[k]=d[k-1]+i; i++;k++; } while(cin >> k,k) cout << d[k] << 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
import math MAX=104729 ROOT=int(math.sqrt(MAX)) #素数以外をはじく prime=[True for i in range(MAX+1)] def prime_list(prime): #2は除外 for i in range(2,MAX,2): prime[i]=False #要素を持つか for x in range(3,ROOT+1): if prime[x]==True: for j in range(x*x,MAX,x): 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 <iostream> using namespace std; int main(){ int p[1000000]; for(int i = 0 ; i < 1000000 ; i++)p[i] = i; p[0] = p[1] = 0; for(int i = 0 ; i*i < 1000000 ; i++){ if(p[i])for(int j = i*2 ; j < 1000000 ; j += i){ p[j] = 0; } } int t[10001] = {0}; int s = 0; for(int i = 0 ; s < 10001 ; 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> #define m 110000 using namespace std; int main(){ int n,cnt; while(1){ cin>>n; if(n==0) break; cnt=0; vector<bool>a(m+1,true); for(int i=2;i*i<=m;i++) if(a[i]) for(int j=i+i;j<=m;j+=i) a[j]=false; long long sum=0; for(int i=2;i<=m;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.*; 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> unsigned long long a[100000],b[200000],c,n; using namespace std; int main(){ for(int i=2;i<200000;i++) for(int j=i*2;j<200000;j+=i) b[j]++; for(int i=2;i<200000;i++)if(!b[i]){a[c+1]+=i+a[c];c++;} while(cin>>n,n)cout<<a[n]<<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
MAX = 105000 is_prime = [True for _ in range(MAX)] is_prime[0] = is_prime[1] = False for i in range(2, int(MAX ** (1 / 2)) + 1): if is_prime[i]: for j in range(i ** 2, MAX, i): is_prime[j] = False primes = [i for i in range(MAX) if is_prime[i]] while True: n = int(input()) if not n: break print...
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.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; /** * Sum of Prime Numbers */ public class Main { static Main main = new Main(); public static void main(String[] args) throws IOException { BufferedReader br = new 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
#include<iostream> using namespace std; int prime[10000]; void GetPrime(int kosuu); int main(){ int n,sum[1000] = {0},cor = 0; GetPrime(10000); while(cin >> n){ if(n == 0) break; for(int i = 0;i < n;i++){ sum[cor] += prime[i]; } cor++; } for(int i = 0;i < cor;i++){ cout << sum[i] << 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 <stdio.h> #define max 200000 int main(void) { long long i, j, k, n, sum[max], now = 0; bool prime[max]; for(i = 0; i < max; ++i) prime[i] = true; prime[0] = prime[1] = false; for(i = 2; i < 500; ++i) if(prime[i]) for(j = 2; i * j < max; ++j) prime[i * j] = false; sum[0] = 0; for(i = 1; i < max; ...
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 num[120000] = {}; int ans[10010] = {}; void prime(){ num[0] = 1; num[1] = 1; for( int i=2 ; i*i<120000 ; i++ ){ if( num[i] == 0 ){ for( int j=2 ; i*j<120000 ; j++ ){ num[i*j] = 1; } } } int cnt = 1; for(int i=2 ; i<120000 ; i++){ if( !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 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; int isprime[104730] = { 0 }; int main() { // for(int i=4; i<104730; i+=2) // isprime[i]=1; isprime[1] = 1; for(int i=2; i*i < 104730; i++) if(isprime[i] == 0) for(int j=2; i*j < 104730; j++) isprime[i*j] = 1; int n; while(1) { cin>>n; if(!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
import random def is_prime(q, k=50): """ ??????????????????????´???°?????????????????¨??????????????????????????°????´???°??????????????????????????? http://d.hatena.ne.jp/pashango_p/20090704/1246692091 """ q = abs(q) # ?¨???????????????§?????????????????§???????????????????????? if q == 2: ret...
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; #define Max 105000 int IsPrime[Max]; int main() { for (int i = 2; i < Max; i++) IsPrime[i] = true; for (int i = 2; i < Max; i++) { if (!IsPrime[i]) continue; for (int j = i + i; j < Max; j += i) { IsPrime[j] = false; } } int n; while (cin >> n, n) { int an...
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 = new Scanner(System.in); int[] v = new int[52365]; for(int i = 0;i < 52365;i++){ v[i] = 1; } int p = 3; while(true){ if(p*p > 104730){ break; }else{ if(v[(p-1)/2] == 0){ p += 2; }el...
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 is_sosu(int n){ for(int i = 2; i*i <= n; i++){ if(n % i == 0) return false; } return true; } int t_sosu(int n){ int count = 0; int total = 0; for(int i = 2; count < n; i++){ if(is_sosu(i)){ count++; total += i; } } return total; } int main(){ int 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 10000 using namespace std; int main(void){ int i = 3; int n = 0; int ps[MAX] = {0,}; ps[n++] = 2; while( n < MAX ){ bool Skip = false; for(int j = 0; j < n; j++){ if( i % ps[j] == 0 ){ Skip = true; break; } } if( !Skip ) ps[n++] = i; i++; } 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
from itertools import * n=range(104730);a=list(n) for i in range(2,323):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
import math isPrime = [True] * 110001 primes = []; def eratos(n): isPrime[0] = isPrime[1] = False for i in range(2,int(math.sqrt(n))): if isPrime[i]: j = 2 * i while j <= n: isPrime[j] = False j = j + i for i in range(2,110000): if isP...
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.*; class Main { static boolean primes []; static void makeTable () { primes = new boolean [200000]; for(int i = 2; i < 200000; i++) { primes[i] = true; } for(int i = 2; i < 200000; i++) { if(primes[i]) { 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
#include<iostream> #include<cstdio> #include<cmath> #include<vector> using namespace std; #define int long long const int PMAX=120000; vector<int> PF(PMAX, 1); void MKPF(){for (int i=2;i<sqrt(PMAX);i++) if(PF[i]==1) for(int j=i*2;j<PMAX;j+=i) PF[j] = 0;} signed main(){ MKPF(); vector<int> sp(10001,0); int ix = 2; f...
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; class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int n,s; boolean is; while(sc.hasNextInt()){ n = sc.nextInt(); if(n == 0)break; s = 0; for(int i = 2; n != 0; i++){ 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 p = [2] NM = 10000 c = 3 while len(p) < NM: m = int(math.sqrt(c)) r = True for i in p: if i > m: break if c % i == 0: r = False break if r: p.append(c) c += 2 while True: n = int(raw_input()) if n == 0: break ...
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<math.h> using namespace std; bool isPrime(int n){ int sqr = sqrt((double)n)+1; if(n%2 == 0)return false; for(int i=3;i<=sqr;i+=2){ if(n%i == 0)return false; } return true; } int main(){ int n; int i, j, sum; while(cin >> n){ if(n==0)break; if(n==1)cout << "2" << endl; else...
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() { bool prime[1000000]; long long int ans[20000]; ans[0]=0; int c=1; for(int i=0;i<1000000;i++) prime[i]=true; for(int i=2;i<1000000;i++) { if(prime[i]) { if(c<20000) ans[c]=ans[c-1]+i; c++; for(int j=i+i;j<1000000;j+=i) pr...
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): p=[True]*n p[0]=p[1]=False for i in range(2,int(n**0.5)+1): if p[i]: for j in range(i*i,n,i): p[j]=False prime =[i for i in range(2,n) if p[i]] return prime def function(n): return sum(A[:n]) A=sieve(110000) while True: n=int(input()) if n==0: break print(function(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
from math import sqrt, ceil, pow class SieveOfAtkin: """ ??¢??????????????? https://github.com/mccricardo/sieve_of_atkin/blob/master/sieve_of_atkin.py """ def __init__(self, limit): self.limit = limit self.primes = [] self.sieve = [False] * (self.limit + 1) def flip(self, 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 <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) #define shosu(n) setprecision(n) #define INF 1000000000; using namespace std; bool sosu(int n) { if (n <= 1) return false; for (int i = 2; i * i <= n; i++) if (n % i == 0) return false; return true; } int main() { long long 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
import java.util.ArrayList; import java.util.Scanner; public class Main { private Scanner sc; public static void main(String[] args) { new Main(); } public Main() { sc = new Scanner(System.in); int[] prime = new int[130000]; for (int i = 0; i < prime.length; i++) { prime[i] = 1; } for (int 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> bool isprime( int n ) { for( int i = 2; i * i <= n; i++ ){ if( n % i == 0 ) return false; } return true; } int main() { int n; while( 1 ){ std::cin >> n; if( !n ) break; int i = 2, p = 0, s = 0; while( p < n ){ if( isprime( i ) ){ s += i; p++; } 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 <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)+1)+1;i++){ x=s[i]; if (x) for (j=i+x;j<h;j+=x) s[j]=0; } s[0]=2; 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
import math p, c = [2], 3 while len(p) < 10000: m = int(math.sqrt(c)) r = True for i in p: if i > m: break if c % i == 0: r = False break if r: p.append(c) c += 2 while True: n = int(raw_input()) if n == 0: break prin...
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 math r = 105000 sqrt = int(math.sqrt(r)) p = [1]*r p[0] = 0 for i in range(1,sqrt): if p[i]: for j in range(2*i+1,r,i+1): p[j] = 0 prime = [0 for i in range(11000)] j = 0 for i in range(len(p)): if p[i]: prime[j] = i+1 j += 1 while True: n = int(raw_inp...
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(){ int n; while(cin >> n,n){ int v[1000000]; for(int i=0;i<1000000;i++) v[i]=1; v[0]=v[1]=0; for(int i=2;i*i<1000000;i++){ if(v[i]){ for(int j=i*2;j<1000000;j+=i){ v[j]=0; } } } long s=0,i=0; while(n--){ while(!v[i])i++; 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
#include <iostream> using namespace std; int prime(int n) { if(n < 2){ return 0; } else 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 argc, char **argv) { int n, s; 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
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