結果

問題 No.800 四平方定理
ユーザー startcppstartcpp
提出日時 2019-03-17 22:38:22
言語 C++11
(gcc 8.5.0)
結果
AC  
実行時間 151 ms / 2,000 ms
コード長 530 bytes
コンパイル時間 298 ms
使用メモリ 103,460 KB
最終ジャッジ日時 2023-02-11 09:40:57
合計ジャッジ時間 3,602 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 2 ms
4,472 KB
testcase_01 AC 3 ms
5,192 KB
testcase_02 AC 2 ms
4,772 KB
testcase_03 AC 2 ms
4,828 KB
testcase_04 AC 2 ms
4,752 KB
testcase_05 AC 2 ms
4,900 KB
testcase_06 AC 3 ms
5,536 KB
testcase_07 AC 2 ms
5,304 KB
testcase_08 AC 3 ms
4,932 KB
testcase_09 AC 3 ms
5,320 KB
testcase_10 AC 61 ms
52,788 KB
testcase_11 AC 68 ms
56,648 KB
testcase_12 AC 73 ms
58,252 KB
testcase_13 AC 60 ms
51,300 KB
testcase_14 AC 66 ms
54,680 KB
testcase_15 AC 71 ms
58,460 KB
testcase_16 AC 67 ms
55,228 KB
testcase_17 AC 67 ms
55,220 KB
testcase_18 AC 79 ms
62,932 KB
testcase_19 AC 80 ms
62,912 KB
testcase_20 AC 2 ms
3,500 KB
testcase_21 AC 2 ms
3,376 KB
testcase_22 AC 79 ms
63,036 KB
testcase_23 AC 151 ms
103,460 KB
testcase_24 AC 135 ms
95,656 KB
testcase_25 AC 149 ms
103,196 KB
testcase_26 AC 1 ms
3,452 KB
testcase_27 AC 2 ms
3,484 KB
testcase_28 AC 136 ms
95,272 KB
testcase_29 AC 143 ms
99,440 KB
testcase_30 AC 137 ms
95,424 KB
testcase_31 AC 124 ms
88,964 KB
testcase_32 AC 136 ms
96,596 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#define int long long
using namespace std;

int cnt1[8000001];	//x^2 + y^2
int cnt2[8000001];	//z^2 - w^2 + D
int n, d;

signed main() {
	int i, j;
	
	cin >> n >> d;
	
	for (i = 1; i <= n; i++)
		for (j = 1; j <= n; j++)
			cnt1[i * i + j * j]++;
	
	for (i = 1; i <= n; i++) {
		for (j = 1; j <= n; j++) {
			int x = i * i - j * j + d;
			if (0 <= x && x <= 2 * n * n) {
				cnt2[x]++;
			}
		}
	}
	
	int ans = 0;
	for (i = 0; i <= 2 * n * n; i++)
		ans += cnt1[i] * cnt2[i];
	cout << ans << endl;
	return 0;
}
0