問題
翻訳を表示Each move removes two coins from one pile and one coin from the other. Either orientation is allowed. You may never remove more coins than remain. Determine whether both piles can end at zero.
Implement coin_piles(left, right).
Input
left: The number of coins in the left pile.
right: The number of coins in the right pile.
Output
Return true if the piles can both be emptied; otherwise return false.
制約
0 ≤ left, right ≤ 1,000,000,000. Two empty piles are already a successful result.
例
入力:
left = 4
right = 2
期待される出力:
expected = True
入力:
long long left = 4;
long long right = 2;
期待される出力:
bool expected = true;
入力:
long left = 4;
long right = 2;
期待される出力:
bool expected = true;
解説
Remove (2, 1) twice: (4, 2) → (2, 1) → (0, 0).
入力:
left = 4
right = 1
期待される出力:
expected = False
入力:
long long left = 4;
long long right = 1;
期待される出力:
bool expected = false;
入力:
long left = 4;
long right = 1;
期待される出力:
bool expected = false;
解説
The only possible first move leaves (2, 0), after which no move can empty the left pile.
参考資料
この課題はCodeUtility用に調整されています。上記の説明と制約に従ってください。