aboutsummaryrefslogtreecommitdiff
path: root/01_introductory_problems/number_spiral_1071.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--01_introductory_problems/number_spiral_1071.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/01_introductory_problems/number_spiral_1071.cpp b/01_introductory_problems/number_spiral_1071.cpp
new file mode 100644
index 0000000..d4df631
--- /dev/null
+++ b/01_introductory_problems/number_spiral_1071.cpp
@@ -0,0 +1,27 @@
1#include <algorithm>
2#include <iostream>
3
4long 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
19int 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}

Generated with cgit - Back to sebastiano.tronto.net