forked from shivanshjaitly/Hackerrank-java-solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalice_and_bob_silly_game .java
41 lines (35 loc) · 1009 Bytes
/
alice_and_bob_silly_game .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
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class day8_sillygame {
static int sieveOfEratosthenes(int n)
{ int count=0;
boolean prime[] = new boolean[n+1];
for(int p = 2; p*p <=n; p++)
{
if(prime[p] ==false)
{
for(int i = p*p; i <= n; i += p)
prime[i] = true;
}
}
for(int i = 2; i <= n; i++)
{
if(prime[i] == false)
count++;
}
return count;}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int g = in.nextInt();
for(int i = 0; i< g; i++){
int n = in.nextInt();
if(sieveOfEratosthenes(n) % 2 == 0)
System.out.println("Bob");
else
System.out.println("Alice");
}
}
}