number_spiral_1071.cpp (424B)
1 #include <algorithm> 2 #include <iostream> 3 4 long long f(long long x, long long y) { 5 long long c = std::max(x, y); 6 if (c % 2) { 7 if (y >= x) 8 return (c-1)*(c-1)+x; 9 else 10 return c*c-y+1; 11 } else { 12 if (y >= x) 13 return c*c-x+1; 14 else 15 return (c-1)*(c-1)+y; 16 } 17 } 18 19 int main() { 20 int t; 21 std::cin >> t; 22 for (int i = 0; i < t; i++) { 23 long long x, y; 24 std::cin >> y >> x; 25 std:: cout << f(x, y) << std::endl; 26 } 27 }