var | desc |
---|---|
Number of tests | |
Number of coins in |
We have two coin piles
- Remove one coin from
$A$ and two coins from$B$ - Remove two coins from
$A$ and one coin from$B$
So the total amount of coins removed in one turn is 3 (either
Also, the bigger of the two piles must not be greater than two times the smaller pile. Because in each turn we take two from one pile and one from the other, so the ratio is 2:1.
So, let's consider the example where
So the total amount of coins in both piles is divisible by three. Then we have to check that the bigger pile
In this case true
.
So if we have input YES
.
In Rust 🦀 code:
fn main() {
let inp: Vec<(u64, u64)> = std::io::read_to_string(std::io::stdin())
.unwrap()
.lines()
.skip(1)
.flat_map(|s| s.split_once(' '))
.map(|(a, b)| (a.parse::<u64>().unwrap(), b.parse::<u64>().unwrap()))
.collect();
for (a, b) in inp {
if (a + b) % 3 == 0 && 2 * a.min(b) >= a.max(b) { println!("YES"); }
else { println!("NO"); }
}
}