Alice and Bob Playing Flower Game - Problem
Alice and Bob are playing a turn-based game on a field with two lanes of flowers between them. There are x flowers in the first lane and y flowers in the second lane.
Game Rules:
- Alice takes the first turn
- In each turn, a player must choose one lane and pick exactly one flower from that lane
- The player who removes the last flower (making both lanes empty) wins the game
Given two integers n and m, count the number of pairs (x, y) where:
- Alice wins the game with optimal play
1 ≤ x ≤ n1 ≤ y ≤ m
Input & Output
Example 1 — Small Grid
$
Input:
n = 3, m = 2
›
Output:
3
💡 Note:
Alice wins for pairs: (1,2), (2,1), (3,2). These have odd sums: 3, 3, 5 respectively.
Example 2 — Symmetric Case
$
Input:
n = 5, m = 4
›
Output:
10
💡 Note:
Odd numbers 1-5: {1,3,5} (3 values), Even numbers 1-4: {2,4} (2 values). Total: 3×2 + 2×2 = 10.
Example 3 — Minimum Case
$
Input:
n = 1, m = 1
›
Output:
0
💡 Note:
Only pair (1,1) has sum 2 (even), so Bob wins. Alice wins in 0 cases.
Constraints
- 1 ≤ n, m ≤ 105
Visualization
Tap to expand
Understanding the Visualization
1
Game Setup
Two lanes with x and y flowers
2
Key Insight
Alice wins when x+y is odd
3
Count Winners
Calculate odd/even combinations
Key Takeaway
🎯 Key Insight: Alice wins exactly when the total flowers (x+y) is odd
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code