結果

問題 No.800 四平方定理
ユーザー BwambocosBwambocos
提出日時 2019-03-17 22:54:40
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 821 bytes
コンパイル時間 1,452 ms
コンパイル使用メモリ 166,172 KB
実行使用メモリ 8,880 KB
最終ジャッジ日時 2023-09-22 09:14:04
合計ジャッジ時間 6,986 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 433 ms
4,380 KB
testcase_09 WA -
testcase_10 TLE -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

int main()
{
	LL N, D;
	in >> N >> D;

	LL ans = 0;
	for (LL x = 1; x <= N; ++x)
	{
		for (LL y = 1; y <= N; ++y)
		{
			LL C = x * x + y * y;
			LL M = D - C;
			if (M == 0)
			{
				if (x == y) ans += (N - 1) * 3 + 1;
				else ans += (N - 2) * 6 + 2 * 3;
			}
			else
			{
				for (LL d = 1; d*d <= std::abs(M); ++d)
				{
					if (M % d != 0) continue;
					LL a = d, b = M / d;
					if (a < b) std::swap(a, b);
					if ((a + b) % 2 == 0)
					{
						LL z = (a + b) / 2;
						LL w = a - z;
						if (b > 0 && z < w) std::swap(z, w);
						if (b < 0 && z > w) std::swap(z, w);
						if (1 <= z && z <= N && 1 <= w && w <= N) ++ans;
					}
				}
			}
		}
	}

	out << ans << std::endl;
}
0