From 5e806a615e24b1f6875a9b4912a58e512a3d7833 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=B7=E5=AE=87=E8=BE=B0?= Date: Tue, 6 Dec 2016 16:07:34 +0800 Subject: [PATCH] bzoj 1041 --- OnlineJudges/lydsy/1041.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 OnlineJudges/lydsy/1041.cpp diff --git a/OnlineJudges/lydsy/1041.cpp b/OnlineJudges/lydsy/1041.cpp new file mode 100644 index 0000000..473410d --- /dev/null +++ b/OnlineJudges/lydsy/1041.cpp @@ -0,0 +1,30 @@ +#include +#include +inline unsigned gcd(unsigned x, unsigned y) +{ + unsigned t; + while (y) t = x % y, x = y, y = t; + return x; +} +unsigned calc(unsigned x) +{ + unsigned ret = 0; + for (unsigned i = 1, j; i * i <= x; i++) + { + j = unsigned(sqrt(x - i * i) + 0.5); + if (i >= j) break; + if (i * i + j * j == x && gcd(i, j) == 1) ret++; + } + return ret; +} +int main() +{ + unsigned n, ans = 1; + scanf("%u", &n); + n <<= 1; + for (unsigned i = 1; i * i <= n; i++) + if (n % i == 0) + ans += calc(n / i) + (i * i == n ? 0 : calc(i)); + printf("%u", ans << 2); + return 0; +} \ No newline at end of file