From 96254947699986c59f0dc63d69fd4b76bd3ed43e Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Mon, 6 Jul 2026 19:08:08 +0200 Subject: Initial commit --- 01_introductory_problems/number_spiral_1071.cpp | 27 +++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 01_introductory_problems/number_spiral_1071.cpp (limited to '01_introductory_problems/number_spiral_1071.cpp') 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 @@ +#include +#include + +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; + } +} -- cgit v1.3