-
Notifications
You must be signed in to change notification settings - Fork 0
/
cut and chocklate.txt
38 lines (24 loc) · 1.02 KB
/
cut and chocklate.txt
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
Cut the Chocolate
Dipen has a chocolate of N by M pieces. He and Damini started playing with this chocolate.
First Dipen takes the chocolate and divides it into two parts by making either a horizontal or a vertical cut. Then, Damini takes one of the available pieces and divides it into two parts by making either a horizontal or a vertical cut. Then Dipen do the same thing again and so on.
The player who cannot make a turn loses. When all pieces are of size 1 * 1 player can not make a turn.
Find who will win if both of them play optimally.
Input:
Two integers denoting N and M.
Output:
Single integer. 1 if Dipen is going to win, 0 if Damini is going to win.
Constraints:
1 <= N <= 10^9
1 <= M <= 10^9
Example:
Input:
N = 1, M = 2
Output:
1
Explanation:
There is only one possible move, so Damini even won't have a chance to make move.
...........................Algorithm......................
if product of (n*m) is return even return 1 else 0 .just think about it
int Solution::solve(int A, int B) {
return !((A*B)%2);
}