Repository navigation
Expand file tree
/
Copy pathCoins.java
More file actions
59 lines (48 loc) · 1.5 KB
/
Copy pathCoins.java
File metadata and controls
59 lines (48 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import java.io.*;
public class Coins {
static class FastScanner {
private final InputStream in = System.in;
private final byte[] buffer = new byte[1 << 16];
private int ptr = 0, len = 0;
private int read() throws IOException {
if (ptr >= len) {
len = in.read(buffer);
ptr = 0;
if (len <= 0) return -1;
}
return buffer[ptr++];
}
long nextLong() throws IOException {
int c;
do {
c = read();
} while (c <= ' ');
long value = 0;
while (c > ' ') {
value = value * 10 + (c - '0');
c = read();
}
return value;
}
}
public static void main(String[] args) throws Exception {
FastScanner fs = new FastScanner();
StringBuilder result = new StringBuilder();
int t = (int) fs.nextLong();
while (t-- > 0) {
long a = fs.nextLong();
long b = fs.nextLong();
boolean possible;
if (a % 2 == 0) {
// y = 0 works: 2 * (a / 2) + b * 0 = a
possible = true;
} else {
// For odd a, b and y must both be odd.
// The smallest valid y is 1.
possible = (b % 2 == 1 && a >= b);
}
result.append(possible ? "YES\n" : "NO\n");
}
System.out.print(result);
}
}