blob: d4df6311cefd90a266a4b884ace14d2b247824bc (
plain)
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
|
#include <algorithm>
#include <iostream>
long long f(long long x, long long y) {
long long c = std::max(x, y);
if (c % 2) {
if (y >= x)
return (c-1)*(c-1)+x;
else
return c*c-y+1;
} else {
if (y >= x)
return c*c-x+1;
else
return (c-1)*(c-1)+y;
}
}
int main() {
int t;
std::cin >> t;
for (int i = 0; i < t; i++) {
long long x, y;
std::cin >> y >> x;
std:: cout << f(x, y) << std::endl;
}
}
|