Skip to content

Commit

Permalink
Divisor Game.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
HackResist authored May 9, 2024
1 parent 422514d commit ddb44bf
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions 09-05-2024/Divisor Game.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//{ Driver Code Starts
#include <bits/stdc++.h>
using namespace std;


// } Driver Code Ends
class Solution {
public:
bool divisorGame(int n) {
// Your Code Start
// Alice will win if `n` is even, as she can always subtract a proper divisor (2) and give Bob an odd number.
// Bob is left with an odd number and can't make a valid move, so Alice wins.
// If `n` is odd, Alice has no valid move, so Bob wins.
return n % 2 == 0;
//Your Code End
}
};

//{ Driver Code Starts.

int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;

Solution obj;
bool ans = obj.divisorGame(n);
if (ans)
cout << "True" << endl;
else
cout << "False" << endl;
}
return 0;
}
// } Driver Code Ends

0 comments on commit ddb44bf

Please sign in to comment.