forked from rajatgoyal715/Hackerrank
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRedJohnIsBack.java
More file actions
67 lines (61 loc) · 1.49 KB
/
RedJohnIsBack.java
File metadata and controls
67 lines (61 loc) · 1.49 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package DynamicProgramming;
import java.util.*;
import java.io.*;
/*
* @author -- rajatgoyal715
*/
public class RedJohnIsBack {
static int max=1000000;
static int sum[]= new int[max];
static boolean prime[] = new boolean[max];
static {
sum[0]=0;
sum[1]=0;
for(int i=2;i<max;i++){
sum[i]=sum[i-1];
if(!prime[i]){
for(int j=2*i;j<max;j+=i){
prime[j]=true;
}
sum[i]++;
}
}
}
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t--!=0){
int n=sc.nextInt();
// System.out.println("N: "+n);
int p=0;
int n1=n/4;
for(int i=0;i<=n1;i++){
p+=comb(n-4*i+i,i);
}
// System.out.println("P: "+p);
// System.out.println("No. of primes: "+sum[p]);
System.out.println(sum[p]);
}
}
public static int fact(int n){
if(n<=1)
return 1;
return fact(n-1)*n;
}
public static int c(int a,int b){
return fact(a)/(fact(a-b)*fact(b));
}
public static int comb(int a,int b){
if(b>a/2){
b=a-b;
}
if(b==0)
return 1;
int num=1,den=1;
for(int i=0;i<b;i++){
num*=(a-i);
den*=(b-i);
}
return num/den;
}
}