結果

問題 No.800 四平方定理
ユーザー apoanzan
提出日時 2019-03-18 10:51:26
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 131 ms / 2,000 ms
コード長 576 bytes
コンパイル時間 1,129 ms
コンパイル使用メモリ 160,632 KB
実行使用メモリ 143,952 KB
最終ジャッジ日時 2024-07-18 01:19:43
合計ジャッジ時間 4,735 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define mp make_pair
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define MOD 1000000007

int MAX = 9e6;

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