-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEating_Chocolate.java
31 lines (27 loc) · 1.1 KB
/
Eating_Chocolate.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
/*
Eating chocolate problem: A and B starts eating a chocolate bar of size x. The participants can eat ith amount of the chocolate where i is the turn parameter, indicating ith bite.
A starts eating from the left while B starts eating from the right. Each participant takes turn to take a bite of ith size. A takes the first bite.
If the size of remaining chocolate bar is less than the required amount to be eaten by A or B in that turn, then they lose. The last participant to take a full bite wins.
The code displays the winner.
*/
import java.util.Scanner;
class Eating_Chocolate{
public static void main(String args[] ) throws Exception {
Scanner sc = new Scanner(System.in);
int x=sc.nextInt();
int i,j;
for(j=1;j<=x;j++)
{
long n=sc.nextLong();
int a;
double d=1+8*n;
double p=Math.sqrt(d);
double q=Math.floor((p-1)/2);
a=(int)q;
if(a%2==1)
System.out.println("A");
else
System.out.println("B");
}
}
}