Search for a command to run...
Progressive hints first, then the full explanation and implementation when you're ready to cash out.
Review status
AI-generated and still unreviewed. Double-check the details before internalizing them.
Hints
Open only as much as you need to keep the solve alive.
Only residues modulo matter. The actual values are just decoration.
If Alice chooses a number with residue , Bob must choose residue .
So the game splits into two independent paired groups: residues and residues .
A completed round always removes one number from each side of exactly one pair. Alice wins if she ever chooses from a residue whose paired residue is already empty.
Bob survives exactly when both pairs start balanced: count() = count() and count() = count(). For numbers , that happens exactly when .
The whole game is about remainders modulo . Nothing else about the numbers matters.
Bob needs Alice's chosen number and his number to satisfy:
That means the possible residue pairings are:
So the blackboard is really just four piles: numbers congruent to modulo .
What happens in one full round?
Suppose Alice chooses residue . Then Bob must choose residue . Net effect: one and one disappear.
Suppose Alice chooses residue . Then Bob must choose residue . Same net effect: one and one disappear.
So for the pair , a completed round always removes one from both piles. Same deal for .
Bob loses immediately if Alice chooses from a pile whose matching pile is empty. For example, if there is a left but no , Alice picks that , Bob has no legal response, and Bob gets cooked.
Now look at a pair, say .
Therefore Bob can only win if both paired groups are perfectly balanced:
where is the number of values from to with remainder modulo .
For consecutive numbers starting at , the residues repeat like this:
All four residue counts are equal exactly when is divisible by .
So:
That's the entire trick. The game looks interactive, but Bob's move is basically forced by residue pairing, so the answer collapses to one modulo check.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void setIO() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
}
int main() {
setIO();
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
cout << (n % 4 == 0 ? "Bob" : "Alice") << '\n';
}
return 0;
}#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void setIO() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
}
int main() {
setIO();
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
cout << (n % 4 == 0 ? "Bob" : "Alice") << '\n';
}
return 0;
}