-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblemE.java
More file actions
37 lines (32 loc) · 723 Bytes
/
ProblemE.java
File metadata and controls
37 lines (32 loc) · 723 Bytes
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
import java.util.*;
public class ProblemE{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
for(int i = 0; i < num; i++){
System.out.println(canWin(sc.nextInt(),sc.nextInt()));
}
}
public static String canWin(int n, int k){
if(win(n,k)){
return "Winner";
}else{
return "Loser";
}
}
public static boolean win(int n, int k){
if(n == 0){
return false;
}else if(n <= k){
return !win(0, k);
}else if(isEven(n/k) && mod(n,k) != 0){
return !win(n-k+1,k);
} else { return !win((n/k)*k,k);}
}
private static boolean isEven(int n){
return (n/2)*2 == n;
}
private static int mod(int n, int base){
return n - (n/base);
}
}