diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2026-07-06 19:08:08 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2026-07-06 19:08:08 +0200 |
| commit | 96254947699986c59f0dc63d69fd4b76bd3ed43e (patch) | |
| tree | 6c4dca945d7f7427c48be234d827fe4d33be02c5 /01_introductory_problems/number_spiral_1071.cpp | |
| download | cses-96254947699986c59f0dc63d69fd4b76bd3ed43e.tar.gz cses-96254947699986c59f0dc63d69fd4b76bd3ed43e.zip | |
Initial commit
Diffstat (limited to '01_introductory_problems/number_spiral_1071.cpp')
| -rw-r--r-- | 01_introductory_problems/number_spiral_1071.cpp | 27 |
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 | |||
| 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 | } | ||
