結果

問題 No.800 四平方定理
ユーザー snrnsidy
提出日時 2021-02-21 22:17:49
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 529 bytes
コンパイル時間 2,128 ms
コンパイル使用メモリ 197,344 KB
最終ジャッジ日時 2025-01-19 03:16:34
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 TLE * 1
other AC * 20 TLE * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

// x^2 + y^2과 w^2 - z^2를 구한다.
unordered_map <int,int> cnt1,cnt2;

int main(void) 
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n,D;
	int res = 0;
	cin >> n >> D;
	
	for(int a=1;a<=n;a++)
	{
		for(int b=1;b<=n;b++)
		{
			cnt1[a*a + b*b]++;
			if(b*b - a*a + D>=0)
			{
				cnt2[b*b - a*a]++;
			}
		}
	}
	
	for(auto it : cnt2)
	{
		long long int way = it.second;
		long long int val = it.first + D;
		res += (cnt1[val]*way);
	}
	
	cout << res << '\n';
	return 0;
}
0