forked from mpfeifer1/Kattis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtractor.cpp
49 lines (37 loc) · 1020 Bytes
/
tractor.cpp
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
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve() {
ll n, m;
cin >> n >> m;
n++; m++;
// The current power of 2 we're moving by
ll shift = 0;
// The current answer
ll total = 0;
// While we're still in range
while(true) {
// There's at most this many extra squares we can reach
ll addhere = (1 << shift);
// Subtract out squares we can't reach in the x dir
ll sub1 = 0;
if(addhere > n) sub1 = addhere - n;
// Subtract out squares we can't reach in the y dir
ll sub2 = 0;
if(addhere > m) sub2 = addhere - m;
// If we can't reach any new squares, quit
if(addhere - sub1 - sub2 <= 0) break;
// Add the squares we can reach to our answer
total += addhere - sub1 - sub2;
// Increase the power of 2
shift++;
}
cout << total << endl;
}
int main() {
int cases;
cin >> cases;
while(cases--) {
solve();
}
}