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 | import static java.util.Arrays.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class Main {
static void tr(Object... os) {
System.err.println(deepToString(os));
}
lon... | JAVA |
p00053 Sum of Prime Numbers | Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7.
Given n, the sum of p (i) from i = 1 to n s
s = p (1) + p (2) + .... + p (n)
Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ... | 7 | 0 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
public class Main {
private static BufferedReader br = null;
private static ArrayList<Integer> prime = null;
private static ArrayList<Integer> sum = null;
p... | JAVA |
p00053 Sum of Prime Numbers | Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7.
Given n, the sum of p (i) from i = 1 to n s
s = p (1) + p (2) + .... + p (n)
Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ... | 7 | 0 | #include<iostream>
using namespace std;
int main(){
long p[10000]={2,3,5,7,11,13,17,19,23},s,n,i,j=8;
while(cin>>n){
if(n==0)break;
while(n>j+1){
s=p[j];
for(;;){
s+=2;
for(i=1;p[i]*p[i]<=s;i++)if(s/p[i]*p[i]==s)break;
if(p[i]*p[i]>s){p[j+1]=s;break;}
}
j++;
}
for(s=i=0;i<n;i++)s+=p[i];
cout<<s<<endl;
}
return 0;
} | CPP |
p00053 Sum of Prime Numbers | Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7.
Given n, the sum of p (i) from i = 1 to n s
s = p (1) + p (2) + .... + p (n)
Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ... | 7 | 0 | def make_ps(n):
nums = [True] * n
nums[0] = nums[1] = False
p = 2
sqrt = n ** 0.5
while p < sqrt:
for i in range(2 * p, n, p):
nums[i] = False
while True:
p += 1
if nums[p]:
break
return [i for i in range(n) if nums[i]]
ps = mak... | 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
count=2
i=3
prime=[2,3]
for i in range(5,1000000,2):
if count==10000:break
check=1
for j in range(2,int(i**0.5)+1):
if i%j==0:
check=0
break
if check==1:
prime.append(i)
count+=1
while 1:
n=int(input())
if n==0:break
print(sum(prime... | 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 <utility>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
using namespace std;
vector<int> p;
bool is_p(int n){
if(n<=1)return false;
for(int i=2; i<=sqrt(n); i++){
if(n%i==0)return false;
}
return true;
}
void make_p(){
int i=2;
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 | from math import sqrt
import sys
sys.setrecursionlimit(100000)
def prime(n):
p = [1 for i in range(n)]
p[0] = 0
prime_ = []
for i in range(2,int(sqrt(n))):
if p[i-1] == 1:
for i in range(2*i,n,i):
p[i-1] = 0
for i in range(n):
if p[i] == 1:
pr... | 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 <cmath>
#include <iostream>
using namespace std;
int main(){
int n,m,sum,w,i;
long img[10000];
img[0]=2;
m=1;
for(long t=3;m<=10000;t+=2){
w=0;
for(i=0;(img[i]<=sqrt(t)) && (i<=m);i++){
if(t % img[i]==0){
w++;
}
}
if(w==0){
img[m]=t;
m++;
}
}
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.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int MAX = 1000000;
int[] p = new int[MAX];
for(int i=2; i<p.length; i++)p[i] = 1;
for(int i=2; i<Math.sqrt(MAX)+1; i++){
for(int j=i*2; j<MAX; j+=i){
p[j] = 0;
}
}
int n = sc.nex... | 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[] args){
Scanner sc = new Scanner(System.in);
int n = 104729;
int counter = 0;
boolean[] isprime = new boolean[n+1];
for (int i = 2; i <= n; i++) {
isprime[i] = true;
}
for (int i = 2; i*i <= n; i++) {
if(isprime[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.*;
public class Main {
Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
new Main();
}
public Main() {
new aoj0053().doIt();
}
class aoj0053 {
int prime[] = new int [300001];
boolean is_prime[] = new boolean[300001];
void sieve(int n){
int p = 0;
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 | import java.util.*;
import java.awt.*;
import java.awt.event.*;
public class Main {
static Scanner sc = new Scanner(System.in);
static int n, ans;
static double p[];
static double[] count = new double[10500];
/**
* @param args
*/
public static void main(String[] args) {
ans = 0;
while(read()){
slove();... | 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 M 104976
using namespace std;
int main() {
int a=2, n, s, l[10001];
bool x[M];
for(int i=2; i<=M; i++) {
x[i]=false;
}
for(int i=2; i<324; i++) {
if(x[i])
continue;
for(int j=i*2; j<M; j+=i) {
if(!x[j])
x[j]=true;
}
}
l[1]=2;
for(int i=3; i<M; i+=2) {
if(!x[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.Arrays;
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
try(Scanner sc = new Scanner(System.in)) {
boolean[] p = new boolean[104730];
int[] s = new int[10001];
int j = 0;
s[j++] = 0;
Arrays.fill(p, true);
for(int i=2; i<104730; i++) {
if... | 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 REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define MAX 1000000
using namespace std;
int prime[MAX];
int main()
{
prime[0] = prime[1] = 0;
REP(i,2,MAX)
{
prime[i] = 1;
}
REP(i,2,MAX)
{
if(prime[i])
{
for(int j = i*2;j < MAX;j += i)
{
pri... | 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
{
static ArrayList<Integer> prime = new ArrayList<>();
public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);
create();
for(;;)
{
int n = scanner.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 | s = [0]
M = 10**6
p = [1]*M
S = 0
for i in range(2,M):
if p[i]:
for j in range(i*i,M,i):
p[j] = 0
S += i; s.append(S)
while 1:
n = input()
if n==0: break
print s[n] | PYTHON |
p00053 Sum of Prime Numbers | Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7.
Given n, the sum of p (i) from i = 1 to n s
s = p (1) + p (2) + .... + p (n)
Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ... | 7 | 0 | #include<iostream>
using namespace std;
typedef long long ll;
const int pMax = 10000;
ll prime[pMax];
bool is_prime[200010];
void sieve(ll n) {
int p = 0;
for (ll i = 0; i <= n; i++) is_prime[i] = true;
is_prime[0] = is_prime[1] = false;
for (ll i = 2; i <= n; i++) {
if (is_prime[i]) {
prime[p++] = 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<stdio.h>
#include<math.h>
int isprime(int x){
int i;
if(x == 2){
return 1;
}
if(x<2||x%2==0){
return 0;
}
i = 3;
while( i <= sqrt(x) ){
if(x%i==0){
return 0;
}
i = i + 2;
}
return 1;
}
int main()
{
int n,c=0,l[10001]={0},j=0;
for(int i=0;i<=104730;i++){
if(isprime(i)){
c+=i;
... | CPP |
p00053 Sum of Prime Numbers | Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7.
Given n, the sum of p (i) from i = 1 to n s
s = p (1) + p (2) + .... + p (n)
Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ... | 7 | 0 | #include <iostream>
#include <vector>
#include <string.h>
using namespace std;
static const int SIZE = 110000;
bool IsPrime[SIZE];
vector<int> Prime;
void calc()
{
memset(IsPrime, 1, sizeof(bool) * SIZE);
for(int i = 2; i < SIZE; ++i)
{
if(IsPrime[i])
{
Prime.push_back(i);
for(int j = 2 * i; j < SIZE; 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>
using namespace std;
int main(){
int n;
bool pr[105000]={0};
for(int i=2;i<400;i++)
for(int j=i;j*i<105000;j++)
pr[j*i]=1;
while(cin>>n,n){
int ans=0,cu=2;
while(n--){
while(pr[cu])cu++;
ans+=cu++;
}
cout<<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 | #include<bits/stdc++.h>
using namespace std;
int main(){
vector<int> p;
p.push_back(2);
for(int i=3;i<=1000000;i+=2){
int k=0;
for(int j=3;j<=sqrt(i);j+=2)
{
if(i%j==0)
{
k=1;
break;
}
}
if(k==0)
p.push_back(i);
}
while(1){
int n;
cin >> n;
if(n == 0)
break... | CPP |
p00053 Sum of Prime Numbers | Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7.
Given n, the sum of p (i) from i = 1 to n s
s = p (1) + p (2) + .... + p (n)
Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ... | 7 | 0 | #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=3; 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) brea... | 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>
#include <cmath>
using namespace std;
bool isprime(int n) {
if (n==2 || n==3) return true;
if (!(n%2)) return false;
if (!(n%3)) return false;
int lim = (int)sqrt((double)n) + 1;
for (int i = 6; i <= lim; i += 6) {
if (!(n%(i-1))) return false;
if (!(n%(i+1))) return false;
}
return true... | CPP |
p00053 Sum of Prime Numbers | Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7.
Given n, the sum of p (i) from i = 1 to n s
s = p (1) + p (2) + .... + p (n)
Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ... | 7 | 0 | #include<iostream>
using namespace std;
int main(){
bool prime[110000];
for(int i=0;i<110000;i++)prime[i]=true;
prime[0]=prime[1]=false;
for(int i=0;i<1005;i++){
if(prime[i]){
for(int j=i*2;j<110000;j+=i)prime[j]=false;
}
}
int a[10000],point=0;
for(int i=2;i<1100... | 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 {
static boolean[] primes;
static void primeSet(final int MAX){
primes = new boolean[MAX+1];
primes[2] = true;
for(int i=3;i<=MAX;i+=2){
primes[i] = true;
}
int rt = (int) Math.sqrt(MAX);
for(int i=3;i<=rt;i+=2){
if(primes[i]){
for(int j=i*2;j<=MAX... | JAVA |
p00053 Sum of Prime Numbers | Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7.
Given n, the sum of p (i) from i = 1 to n s
s = p (1) + p (2) + .... + p (n)
Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ... | 7 | 0 | #include <iostream>
using namespace std;
int main(void){
int prime[10002];
int sum[10002];
prime[1] = 2;
prime[2] = 3;
sum[1] = 2;
sum[2] = 5;
int ptr=3;
for(int num=5; ptr<=10000; num++){
bool f = false;
for(int i=1; i<ptr; i++){
if(num%prime[i]==0) {
f = true;
break;
}
}
if(!f) {
prim... | CPP |
p00053 Sum of Prime Numbers | Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7.
Given n, the sum of p (i) from i = 1 to n s
s = p (1) + p (2) + .... + p (n)
Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ... | 7 | 0 | #include <iostream>
#include <vector>
int main(){
std::vector<int> v;
v.push_back(2);
for(int i = 3;v.size()<10001;i+=2){
bool f = true;
for(int j=0;v[j]*v[j]<=i;j++){
if(!(i%v[j]))f=false;
}
if(f)v.push_back(i);
}
int n;
while(std::cin>>n){
if(!n)break;
int sum=0;
for(;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.Scanner;
public class Main{
static Scanner sc = new Scanner(System.in);
static int[] prin = new int[52365];
static void SystemOut(){
while(sc.hasNext()){
int n=sc.nextInt();
if(n==0){
break;
}
int ans=2;
for(i... | JAVA |
p00053 Sum of Prime Numbers | Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7.
Given n, the sum of p (i) from i = 1 to n s
s = p (1) + p (2) + .... + p (n)
Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ... | 7 | 0 | #include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;
bool isPrime(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(){
int n;
while(cin >> n){
if(n==0){
break;
}
int cnt=0,ans=0,j=0;
while(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;
int n, i = 1, p = 3;
int a[10000];
int main()
{
a[0] = 2;
while (i < 10000) {
int j = 3;
while (j * j <= p) {
if (p % j == 0)
break;
j += 2;
}
if (j * j > p) {
a[i] = a[i - 1] + p;
i++;
}
p += 2;
}
cin >> n;
while (n > 0) {
cout << a[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 | from itertools import *
n=104730;a=list(range(n))
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)+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 <cstdio>
#include <cstring>
using namespace std;
#define MAX 1000001
int main(){
bool p[MAX];
memset(p, true, sizeof(p));
p[1] = p[0] = 0;
for(int i = 0 ; i < MAX ; i++){
if(p[i]){
for(int j = 2 * i ; j < MAX ; j += i){
p[j] = 0;
}
}
}
int n;
while(cin... | CPP |
p00053 Sum of Prime Numbers | Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7.
Given n, the sum of p (i) from i = 1 to n s
s = p (1) + p (2) + .... + p (n)
Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ... | 7 | 0 | import math
NM = 10000
p = [2] * NM
c = 1
a = 3
while c < NM:
m = int(math.sqrt(a))
r = True
for i in p:
if i > m:
break
if a % i == 0:
r = False
break
if r:
p[c] = a
c += 1
a += 2
while True:
n = int(raw_input())
if n == 0... | 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.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
public class Main{
Scanner sc;
static final int INF=1<<28;
static final double EPS=1e-9;
void run(){
int[] p=new int[10001];
int k=1;
for(int i=1; i<p.length; 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;
int main()
{
int n;
while(cin>>n && n){
int sum = 2;
int cnt = 1;
bool flag = true;
for(int i=3;;i+=2){
if(cnt == n){
cout<<sum<<endl;
break;
}
for(int j=2;j*j<=i;j++){
if(i % j==0){
flag = false;
break;
}
}
if(flag){
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 java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int prime[];
int n;
int sum;
int count;
prime = new int[1300000];
for (int i = 2; i * i <= 1300000; i++) {
for (int j = 2; 0 <= i * j && i * j < 1300000; j++) {
prime[i * 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>
#include<math.h>
using namespace std;
int main(){
int prime[1000000];
for(int i = 0; i < 1000000; i++) prime[i] = 1;
prime[0] = 0;
prime[1] = 0;
for(int i = 2; i < sqrt(1000000); i++){
if(prime[i] == 1) for(int j = i*2; j < 1000000; j+=i) prime[j] = 0;
}
while(1){
int 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.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
class Main {
public static void main(String[] args) throws IOException {
doit(args, System.in, System.out);
}
static void doit(String[] args, InputS... | JAVA |
p00053 Sum of Prime Numbers | Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7.
Given n, the sum of p (i) from i = 1 to n s
s = p (1) + p (2) + .... + p (n)
Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ... | 7 | 0 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main{
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String str;
int n;
boolean prime[] = new boolean[110001];
pri... | JAVA |
p00053 Sum of Prime Numbers | Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7.
Given n, the sum of p (i) from i = 1 to n s
s = p (1) + p (2) + .... + p (n)
Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ... | 7 | 0 | #include <iostream>
using namespace std;
int main(){
int n;
while(cin>>n){
if(n==0) break;
int sum=0;
bool prime[1000000];
for(int i=2;i<=999999;i++){
prime[i]=true;
}
for(int j=2;j<=999999;j++){
if(prime[j]){
for(int k=2*j;k<=999999;k+=j){
prime[k]=false;
}
}
}
int m=0;
for(in... | 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 | N = 104743
p = [1]*(N + 1)
for i in range(4, N + 1, 2): p[i] = 0
a = [2]
for i in range(3, N + 1, 2):
if p[i] == 1:
a.append(a[-1] + i)
for j in range(3*i, N + 1, 2*i): p[j] = 0
while True:
n = int(input())
if n == 0: break
print(a[n - 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 <bits/stdc++.h>
using namespace std;
bool pn[1000001];
int main()
{
pn[0] = pn[1] = false;
for (int i = 2; i <= 1000001; i++){
pn[i] = true;
}
for (int i = 2; i <= 1001; i++){
if (pn[i]){
for (int j = i * 2; j <= 1000001; j += i){
pn[j] = false;
}
}
}
int n;
whil... | 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 prime[10000];
bool num[110000]; for(int i=0;i<110000;i++) num[i]=false;
num[0]=num[1]=true;
for(int i=2;i<110000;i++)
{
if(num[i]==true) continue;
for(int j=i*2;j<110000;j+=i) num[j]=true;
}
int pnt=0;
for(int i=0;i<110000;i++)
{
if(num[i]==false)... | CPP |
p00053 Sum of Prime Numbers | Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7.
Given n, the sum of p (i) from i = 1 to n s
s = p (1) + p (2) + .... + p (n)
Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ... | 7 | 0 | #include<iostream>
#include<cstdio>
using namespace std;
int main(){
int n[1000000]={0};
int x, ans=0,l;
for(int i=1; i<=999999; i++){
if(i==1) n[i]=-1;
else if(n[i]==0){
for(int k=2; k*i<=999999; k++){
n[k*i]=-1;
}
}
}
while(cin>>x){
if(x==0) break;
ans=0;
l=0;
for(int j=1; l<x; 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 <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <set>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
void sieve(bool* pn){
for(int i=2;i<sqrt(105000.);++i){
if(pn[i]){
for(int j=i*2;j<105000;j+=i){
pn[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.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> listX = new ArrayList<Integer>();
public static void main(String[] args) {
Scanner st... | 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>
using namespace std;
#define N 1000000
int main(){
bool prime[N+1];
for(long i=2; i<=N; ++i) prime[i]=true;
for(long i=2; i<=N; ++i){
if(prime[i]){
for(long j=2; i*j<=N; ++j) prime[i*j]=false;
}
}
while(1){
int n ,count=1;
long ans=2;
scanf(" %d", &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.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String line = null;
// エラトステネスの篩
int MAX = 1000000;
int num = (MAX - 3) / 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>
using namespace std;
#define N 105000
int main()
{
int a[N]={0},n,i,j,z,sum;
for(i=2;i<=N/2;i++){
if(a[i]==0){
for(j=2;j*i<=N;j++){
a[i*j]=1;
}
}
}
while(1){
cin>>n;
if(n==0)break;
else {
z=0;
sum=0;
for(i=2;i<N;i++){
if(n==z)bre... | 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>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
bool is_prime[1000001];
int prime_sum[1000001];
int main() {
memset(is_prime, 1, sizeof(is_prime));
is_prime[0] = is_prime[1] = false;
int p = 0, cnt = 0;
for (int i = 2; i <= 1000000; i++) {
if (is_prime[i]) {
cnt += i;
pri... | 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 List<Integer> prime = new ArrayList<Integer>();
static boolean[] isPrime = new boolean[300000];
static void primeCalc()
{
for(int i = 0; i < isPrime.length; ++i)
{
isPrime[i] = true;
}
isPrime[0] = isPrime[1] = false;
for(int i = 2; i < isPrime.length; ++... | 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>
using namespace std;
int p[10000];
bool isPrime[1000000];
int main(void){
int pnum=0;
//但多
fill(isPrime,isPrime+1000000,true);
for(int i=2;pnum<10000;i++){
if(isPrime[i] == true){
p[pnum++] = i;
for(int j=2;i*j<1000000;j++){
isPrime[i*j] = false;
... | CPP |
p00053 Sum of Prime Numbers | Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7.
Given n, the sum of p (i) from i = 1 to n s
s = p (1) + p (2) + .... + p (n)
Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ... | 7 | 0 | #include<iostream>
#include<cstdio>
using namespace std;
bool prime[1000000];
int main(){
int n;
while (cin >> n, n){
long long sum = 0;
int cntprime = 0;
for (int i = 2;; i++){
if (prime[i]) continue;
cntprime++;
sum += i;
if (cntprime == n){
printf("%d\n", sum);
break;
}
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 | #include <iostream>
using namespace std;
typedef unsigned long long int ull;
int main()
{
const int PN=104729+1;
bool checked[PN] = {};
const int N=10000+1;
ull s[N] = {};
for( int i=2, l=1; i<PN; ++i )
{
if ( !checked[i] ) {
for( int j=i; j<PN; j+=i ) {
ch... | 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 | p = [1] * (110000 + 1)
p[0], p[1] = 0, 0
for i in range(2, int(110000 ** 0.5) + 1):
if not p[i]:
continue
for j in range(2 * i, 110000 + 1, i):
p[j] = 0
p_num = [i for i in range(110000) if p[i] == 1]
while 1:
n = int(input())
if n == 0:
break
print(sum(p_num[: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 <algorithm>
#define N 105000
using namespace std;
int main()
{
int n = 0;
bool prime[N];
fill(prime, prime+N, true);
for(int i = 2; i < N; ++i){
if(prime[i])
for(int j = i+i; j < N; j += i)
prime[j] = false;
}
while(cin>>n && n){
int sum = 0;
for(int i ... | CPP |
p00053 Sum of Prime Numbers | Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7.
Given n, the sum of p (i) from i = 1 to n s
s = p (1) + p (2) + .... + p (n)
Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ... | 7 | 0 | import java.util.Scanner;
class Main
{
public static void main(String args[])
{
boolean not[] = new boolean[1000000];
not[0] = true;
not[1] = true;
for (int i = 2; i * i < 1000000; i++)
{
if (not[i]) continue;
for (int x = (i << 1); x < 1000000; x += i)
{
if (not[x]) continue;
not[x] = tru... | 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 loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) for(int i=0;i<a;i++)
using namespace std;
int main(){
bool prime[1000001];
rep(i, 1000001){
prime[i] = true;
}
prime[0] = prime[1] = false;
loop(i, 2, 1001){
if (prime[i]){
for (int j = i * 2; j < 1000001; j += i){
prime... | CPP |
p00053 Sum of Prime Numbers | Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7.
Given n, the sum of p (i) from i = 1 to n s
s = p (1) + p (2) + .... + p (n)
Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ... | 7 | 0 | import math
r = 105000
sqrt = int(math.sqrt(r))
p = [1]*r
p[0] = 0
for i in range(1,sqrt):
if p[i]:
p[2*i+1::i+1] = [0 for x in range(2*i+1,r,i+1)]
s = [0 for i in range(11000)]
s[0] = 2
k = 1
for i in range(2,r):
if p[i]:
s[k] = i+1+s[k-1]
k += 1
while True:
n = int(raw_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<cstdio>
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(;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 | 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
while True:
n = int(raw_input())
if not n:
break
i, num, sum = 0, 0, 0
while num < n:
if p[i] == 1:
num += 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.Arrays;
public class Main {
// エラトステネスのふるい(n以下の素数を求める)
public static boolean[] sieve (int n) {
boolean[] isPrime = new boolean[n + 1];
Arrays.fill(isPrime, true);
for (int i = 4; i < isPrime.length; 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.Scanner;
public class Main {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
while(true){
int num = input.nextInt();
if(num == 0)break;
System.out.println(prime(num));
}
}
public static long prime(int n){
long sum =... | JAVA |
p00053 Sum of Prime Numbers | Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7.
Given n, the sum of p (i) from i = 1 to n s
s = p (1) + p (2) + .... + p (n)
Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ... | 7 | 0 | #include<iostream>
#include<vector>
using namespace std;
#define rep(i,a) for(int i = 0 ; i < a ; i ++)
#define loop(i,a,b) for(int i = a ; i < b ; i ++)
const int M = (1e6);
bool p[M];
vector<long long int>sum;
void isPrime(){
rep(i,M)p[i] = true;
p[0] = p[1] = false;
sum.push_back(0);
loop(i,2,M){
if(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 math
r = 200000
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
while True:
n = int(raw_input())
if not n:
break
i, num, sum = 0, 0, 0
while num < n:
if p[i] == 1:
num += 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 | # 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 <bits/stdc++.h>
using namespace std;
#define MAX 1000000
int main()
{
vector<int> p;
bool prime[MAX];
fill(prime, prime + MAX, 1);
prime[0] = prime[1] = 0;
for (int i = 2; i < MAX; i++) {
if (prime[i]) {
p.push_back(i);
for (int j = 2*i; j < MAX; 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 <stdio.h>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define NUM (200000)
int pt[NUM];
int sum[12000];
int main() {
vector<int> ps;
for (int i = 2; i < NUM; i++) if (pt[i] == 0) {
ps.push_back(i);
for (int j = i+i; j < NUM; j+=i) pt[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 <cmath>
using namespace std;
int a[20000] = {};
int sosuu() {
a[0] = 0;
int k = 1, z;
for (int i = 2; i<100000 || k<10001; i++) {
z = 0;
for (int j = 2; j <= sqrt(i); j++) {
if (i%j == 0) {
z++;
break;
}
}
if(z==0){
a[k] = i;
k++;
}
}
return 0;
}
int ma... | CPP |
p00053 Sum of Prime Numbers | Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7.
Given n, the sum of p (i) from i = 1 to n s
s = p (1) + p (2) + .... + p (n)
Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ... | 7 | 0 | n = 104730
c = [1 for i in range(n)]
c[0] = 0
i = 2
while i**2 <= n:
j = i*2
while j <= n:
c[j - 1] = 0
j += i
i += 1
while True:
n_i = int(input())
if n_i == 0:
break
s = 0
i = 0
j = 0
while i < n_i:
j += 1
if c[j] == 1:
s += j + ... | 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 <cmath>
#include <vector>
using namespace std;
int main(){
vector<int> array;
bool prime[1000001];
long long int n,t,a = 0,i,j = 0;
for (i = 3; i <= 1000000; i += 2){
prime[i] = true;
}
prime[2] = true;
for (i = 3; i <= 1000; i += 2){
if (prime[i] == 1){
for (j = 3; j <= 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<cstdio>
int main(){
int f[104730] = {1,1};
int a[10001] = {};
int n = 0,t = 1;
for(int i = 2; i < 52365; i++){
f[i * 2] = 1;
}
for(int i = 3; i <= 324; i += 2){
for(int j = 3; j * i < 104730; j += 2){
f[i*j] = 1;
}
}
for(int i = 1; i < 10001; i++){
while(t){
n++;
t = f[n];
}
a[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<bits/stdc++.h>
using namespace std;
const int SIZE=200000;
bool f[SIZE];
int main(){
vector<int>p;
f[0]=f[1]=true;
for(int i=2;i<SIZE;i++){
if(f[i])continue;
p.push_back(i);
for(int j=i+i;j<SIZE;j+=i)f[j]=true;
}
for(int i=1;i<p.size();i++)p[i]+=p[i-1];
in... | 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>
#include <algorithm>
using namespace std;
int main(){
bool f[105000];
int n;
long long int sum[105000];
memset(f,false,sizeof(f));
sum[0]=0;
for(int i=2;i*i<=105000;i++){
if(f[i])continue;
for(int j=i*i;j<105000;j+=i)f[j]=true;
}
int k=1;
for(int j=2;j<=105000;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>
using namespace std;
bool sosu(int n)
{
for(int i=2;i*i<=n;i++)
{
if(n%i==0)return false;
}
return true;
}
int main(void)
{
while(1)
{
int n;
cin>>n;
if(n==0)break;
int ans;
ans=0;
int i,j;
for(i=0,j=2;i<n;j++)
{
if(sosu(j))
{
ans+=j;
i++;
}
}
cout<<ans... | CPP |
p00053 Sum of Prime Numbers | Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7.
Given n, the sum of p (i) from i = 1 to n s
s = p (1) + p (2) + .... + p (n)
Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ... | 7 | 0 | #include <iostream>
#include <vector>
using namespace std;
const int Max = 1000000;
bool P[Max];
void eratos(){
for( int i = 0;i < Max;i++ ) P[i] = true;
P[0] = P[1] = false;
for( int i = 2;i * i < Max;i++ ) if( P[i] ) for( int j = 2;i * j < Max;j++ ) P[i * j] = false;
}
int main(int argc, char const* argv[])
{
... | 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[]){
new Main().mainrun();
}
private Scanner scan;
int max = 100000000;
boolean[] Prime = new boolean[max];
private void mainrun() {
scan = new Scanner(System.in);
Arrays.fill(Prime, true);
Prime[... | 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 {
Scanner sc = new Scanner(System.in);
public void run() {
ArrayList<Integer> primes=new ArrayList<Integer>();
for(int i=2;i<120000;i++){
boolean isprime=true;
for(int prime:primes){
if(i%prime==0){
isprime=false;
break;
}
if( prime*prime>i){
br... | 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 static java.lang.Math.*;
import static java.util.Arrays.*;
import java.util.*;
import java.io.*;
public class Main {
ArrayList<Integer> primes;
int N = 10000000;
void prime() {
boolean[] p = new boolean[N+1];
for(int i=2;i<=N;i++) if( !p[i] ) {
primes.add(i);
for(int j=2*i;j<=N;j+=i) p[j] = t... | JAVA |
p00053 Sum of Prime Numbers | Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7.
Given n, the sum of p (i) from i = 1 to n s
s = p (1) + p (2) + .... + p (n)
Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ... | 7 | 0 | import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int[] prime = new int[999999];
prime[0] = 2;
int num = 1;
while(s.hasNext()) {
int n = s.nextInt();
if (n==0)
break;
if (num < ... | JAVA |
p00053 Sum of Prime Numbers | Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7.
Given n, the sum of p (i) from i = 1 to n s
s = p (1) + p (2) + .... + p (n)
Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ... | 7 | 0 | import java.io.*;
import java.util.*;
public class Main {
public static final int numMax = 300000;
private static int[] primes = new int[10000];
public static void main(String[] argv) throws IOException {
boolean[] primeFlag = new boolean[numMax];
Arrays.fill(primeFlag, true);
int... | JAVA |
p00053 Sum of Prime Numbers | Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7.
Given n, the sum of p (i) from i = 1 to n s
s = p (1) + p (2) + .... + p (n)
Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ... | 7 | 0 | #include<iostream>
#include<cstring>
using namespace std;
bool erats[1000001];
int main(){
memset( erats, 0, sizeof(erats) );
erats[0] = erats[1] = true;
for( int i=2; i<500000; i++ ){
for( int j=i+i; j<=1000000; j+=i ){
erats[j] = true;
}
}
int n;
while( cin >> n, n>0 ){
int ret=0, cnt=0;
for( int i... | CPP |
p00053 Sum of Prime Numbers | Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7.
Given n, the sum of p (i) from i = 1 to n s
s = p (1) + p (2) + .... + p (n)
Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ... | 7 | 0 | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
int[] primeList = new int[10001];
int limit = 104743;
primeList[0] = 2;
primeList[1] = 3;
int count = 2;
for (int i = 5; i <= limit; i += 2) {
boolean wflag = true;
... | JAVA |
p00053 Sum of Prime Numbers | Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7.
Given n, the sum of p (i) from i = 1 to n s
s = p (1) + p (2) + .... + p (n)
Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ... | 7 | 0 | #include <iostream>
#include <vector>
#define N 1000000
using namespace std;
int main(){
bool isP[N];
vector<long> v;
for( int i=0;i<N;i++ ) isP[i]=true;
v.push_back( 0 );
// int k=0;
for( int i=2;i<N && v.size()<=N+1 ;i++ ){
if( !isP[i] ) continue;
v.push_back( i+v.back() );
// ++k;
... | CPP |
p00053 Sum of Prime Numbers | Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7.
Given n, the sum of p (i) from i = 1 to n s
s = p (1) + p (2) + .... + p (n)
Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ... | 7 | 0 | #include<iostream>
#include<algorithm>
using namespace std;
int p[105000];
long long s[105000];
int main(){
p[0] = p[1] = 1;
for(int i = 2;i * i <= 105000;i++){
if(p[i])continue;
for(int j = i * i;j < 105000;j+=i){
p[j] = 1;
}
}
int r = 1;
for(int j = 0;j <= 105000;j++){
if(p[j] == 0){
... | CPP |
p00053 Sum of Prime Numbers | Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7.
Given n, the sum of p (i) from i = 1 to n s
s = p (1) + p (2) + .... + p (n)
Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ... | 7 | 0 | #include<iostream>
#include<vector>
#define MAX 1000000
using namespace std;
int main(){
vector<int> prid(MAX);
vector<int> pri(MAX);
int k=1;
for(int i=0;i<MAX;i++)
prid[i]=1;
prid[0]=0;
prid[1]=0;
for(int i=0;i*i<MAX;i++){
if(prid[i]){
for(int j=i*2;j<MAX;j+=i)
prid[j]=0;
}
}
for(int i=0;i<MAX;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<algorithm>
int main(){
const int N =104729+1;
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]=false;
}
int n;
int s;
int count;
while(scanf("%d",&n),n){
i=3;s=... | 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_checker(n, option = False) -> list:
p = [False, True, False, False, False, True] * (n // 6 + 1)
del p[n + 1:]
p[1 : 4] = False, True, True
for x in range(5, int(n**.5 + 1)):
if p[x]:
p[x * x :: 2*x] = [False] * ((n // x - x) // 2 + 1)
return [e for e, q in enumerate(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 | // 2011/04/02 Tazoe
#include <iostream>
using namespace std;
int main()
{
int p[10001];
p[0] = 0;
p[1] = 2;
for(int i=2; i<=10000; i++){
for(p[i]=p[i-1]+1; true; p[i]++){
bool prm = true;
for(int j=1; j<=i-1; j++){
if(p[i]%p[j]==0){
prm = false;
break;
}
}
if(prm)
break;
els... | 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 | prim=[True]*1000000
prim[0],prim[1]=False,False
for i in range(2,1000):
if prim[i]:
for j in range(i*2,1000000,i):
prim[j]=False
prime=[i for i,j in enumerate(prim) if j==True]
while True:
n=int(input())
if n==0:
break
print(sum(prime[: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.math.*;import java.util.*;class Main{public static void main(String[]z){int p[]=new int[10001],i=0;for(BigInteger x=BigInteger.ONE;i++<10000;p[i]=p[i-1]+x.intValue())x=x.nextProbablePrime();for(Scanner s=new Scanner(System.in);(i=s.nextInt())>0;)System.out.println(p[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>
#include <math.h>
#define N 1000001
using namespace std;
int main(void){
bool isprime[N];
for(int i=0;i<N;i++) isprime[i]=true;
int upto = (int)sqrt(N);
for(int i=2;i<=upto;i++){
if(isprime[i]){//消されてなければその倍数を消す
for(int j=2;i*j<=N;j++) isprime[i*j] = false;
}
}
int n;
while(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 |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
public class Main {
public static void main(String[] args) throws NumberFormatException, IOException {
// TODO Auto-generated method stub
BufferedReader br = new BufferedReader(new InputStrea... | 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 flag[1000000];
int ans[10001];
int main()
{
int cnt=1;
for(int i = 2; i < 1000000; ++i)
{
if(!flag[i])
{
ans[cnt]=ans[cnt-1]+i;
cnt++;
if(cnt==10001) break;
for(int j = i*2; j < 1000000; j+=i)
{
flag[j]=true;
}
}
}
int n;
while(cin>>n,n) co... | CPP |
p00053 Sum of Prime Numbers | Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7.
Given n, the sum of p (i) from i = 1 to n s
s = p (1) + p (2) + .... + p (n)
Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ... | 7 | 0 | 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
s = [0 for i in range(11000)]
s[0] = 2
k = 1
for i in range(2,r):
if p[i]:
s[k] = i+1+s[k-1]
k += 1
while True:
n = int(raw... | PYTHON |
p00053 Sum of Prime Numbers | Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7.
Given n, the sum of p (i) from i = 1 to n s
s = p (1) + p (2) + .... + p (n)
Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ... | 7 | 0 | #include <stdio.h>
bool RB[105000];int ans[10005];int main() {int i,j;for (i=0;i<105000;RB[i++]=true);for (i=2;i<325;i++) if (RB[i]) for (j=i*i;j<105000;RB[j]=false,j+=i);for (i=2,j=1,ans[0]=0;i<105000;i++) if (RB[i]) ans[j]=ans[j-1]+i,j++;while (1) {scanf("%d",&i);if (!i) return 0;printf("%d\n",ans[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<algorithm>
#include<vector>
using namespace std;
#define MAX 105000
int main(){
bool prime[MAX + 1] = {};
int sum = 0, cnt = 0;
vector< int > vc;
vc.push_back(2);
for(int i = 3 ; cnt < 10001 ; i += 2 ){
if(!prime[i]){
vc.push_back(i + vc[cnt++]);
for(int j = 3 ; i ... | CPP |
p00053 Sum of Prime Numbers | Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7.
Given n, the sum of p (i) from i = 1 to n s
s = p (1) + p (2) + .... + p (n)
Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 ... | 7 | 0 | prim=[True]*1000000
prim[0]=prim[1]=False
for i in range(2,350):
if prim[i]:
for j in range(i*2,110000,i):
prim[j]=False
prime=[i for i,j in enumerate(prim) if j==True]
while True:
n=int(input())
if n==0:
break
print(sum(prime[:n])) | PYTHON3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.