結果

問題 No.152 貯金箱の消失
ユーザー data9824data9824
提出日時 2015-05-26 18:32:41
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 69 ms / 5,000 ms
コード長 745 bytes
コンパイル時間 896 ms
コンパイル使用メモリ 60,788 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-20 13:34:26
合計ジャッジ時間 1,479 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 3 ms
4,376 KB
testcase_07 AC 11 ms
4,376 KB
testcase_08 AC 67 ms
4,380 KB
testcase_09 AC 69 ms
4,380 KB
testcase_10 AC 53 ms
4,376 KB
testcase_11 AC 30 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cmath>

using namespace std;

long long gcd(long long x, long long y) {
	do {
		if (x < y) {
			std::swap(x, y);
		}
		x = x % y;
	} while (x > 0LL);
	return y;
}

int main() {
	long long l;
	cin >> l;
	long long patterns = 0;
	long long total = l / 4;
	for (long long m = 1; m < (long long)sqrt(total); ++m) {
		for (long long n = 1; n < m; ++n) {
			if ((m - n) % 2 == 0) {
				continue;
			}
			if (gcd(m, n) > 1) {
				continue;
			}
			long long a = m * m - n * n;
			long long b = 2 * m * n;
			long long c = m * m + n * n;
			if (a + b + c > total) {
				continue;
			}
			if (a * a + b * b != c * c) {
				continue;
			}
			++patterns;
			patterns %= 1000003;
		}
	}
	cout << patterns << endl;
	return 0;
}
0