From 963dbd04e0f2f0cb2d669f73413b1e5e36c2c9c9 Mon Sep 17 00:00:00 2001 From: nihonium Date: Sun, 20 Feb 2022 18:57:30 +0300 Subject: [PATCH] q --- numbers/q.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 numbers/q.c diff --git a/numbers/q.c b/numbers/q.c new file mode 100644 index 0000000..189bc8b --- /dev/null +++ b/numbers/q.c @@ -0,0 +1,33 @@ +#include + + +int is_equal(const int *a, int n); + +int main() { + int a[3]; + int n = 0; + int res = 0; + scanf("%d", &n); + + for (int i = 1; i < n; ++i) + for (int j = 0; j < n; ++j) + for (int k = 0; k < n; ++k) { + a[0] = i; + a[1] = j; + a[2] = k; + if (is_equal(a, n)) + res = i * n * n + j * n + k; + } + printf("%d", res); + + return 0; +} +int is_equal(const int* a, int n) { + long long q1 = 1ll* a[0] * n * n + a[1] * n + a[2]; + long long q2 = q1 * q1; + + if (q2 % n == a[2] && (q2 / n) % n == a[1] && (q2 / (n * n)) % n == a[0]) + return 1; + + return 0; +}