-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathE10.java
45 lines (43 loc) · 1010 Bytes
/
E10.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
https://www.hackerrank.com/contests/projecteuler/challenges/euler010/problem
import java.util.Scanner;
import java.util.StringTokenizer;
class E10_
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
long ar[]=new long[1000000+1];
boolean r[]=find(1000000);
long sum2=0;
for(int x=1;x<=1000000;x++)
{
if(!r[x])
{
sum2+=x+1;
}
ar[x]=sum2;
}
for(int x=0;x<t;x++)
{
int n=sc.nextInt();
System.out.println(ar[n-1]);
}
}
public static boolean[] find(int n)
{
boolean ar[]=new boolean[n+1];
ar[0]=true;
for(int x=2;x<=Math.sqrt(n);x++)
{
if(!ar[x-1])
{
for(int y=x*x;y<n;y+=x)
{
ar[y-1]=true;
}
}
}
return ar;
}
}