From 96254947699986c59f0dc63d69fd4b76bd3ed43e Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Mon, 6 Jul 2026 19:08:08 +0200 Subject: Initial commit --- 07_mathematics/josephus_queries_2164.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 07_mathematics/josephus_queries_2164.cpp (limited to '07_mathematics/josephus_queries_2164.cpp') diff --git a/07_mathematics/josephus_queries_2164.cpp b/07_mathematics/josephus_queries_2164.cpp new file mode 100644 index 0000000..b17f3c9 --- /dev/null +++ b/07_mathematics/josephus_queries_2164.cpp @@ -0,0 +1,17 @@ +#include + +int f(int n, int k, int m) { + int h = n/2 + m*(n%2); + if (n == 1) return 1; + if (k <= h) return 2*k-m; + return 2*f(n-h, k-h, m^(n%2))+m-1; +} + +int main() { + int q, n, k; + std::cin >> q; + for (int i = 0; i < q; i++) { + std::cin >> n >> k; + std::cout << f(n, k, 0) << "\n"; + } +} -- cgit v1.3