結果

問題 No.800 四平方定理
コンテスト
ユーザー leaf_1415
提出日時 2019-03-17 21:32:40
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 54 ms / 2,000 ms
コード長 486 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 544 ms
コンパイル使用メモリ 76,580 KB
実行使用メモリ 64,596 KB
最終ジャッジ日時 2026-03-29 11:47:00
合計ジャッジ時間 2,349 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <vector>
#include <algorithm>
#define llint long long

using namespace std;

llint n, d;
llint cnt[16000005];

int main(void)
{
	cin >> n >> d;
	
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++){
			cnt[i*i+j*j]++;
		}
	}
	//sort(vec.begin(), vec.end());
	
	llint ans = 0;
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++){
			llint x = d - (i*i-j*j);
			if(x < 0) continue;
			ans += cnt[x];
		}
	}
	cout << ans << endl;
	
	return 0;
}
0