結果
| 問題 | 
                            No.800 四平方定理
                             | 
                    
| コンテスト | |
| ユーザー | 
                             ty70
                         | 
                    
| 提出日時 | 2019-03-18 00:33:42 | 
| 言語 | C++11(廃止可能性あり)  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                RE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 763 bytes | 
| コンパイル時間 | 1,503 ms | 
| コンパイル使用メモリ | 158,176 KB | 
| 実行使用メモリ | 42,368 KB | 
| 最終ジャッジ日時 | 2024-07-08 07:48:30 | 
| 合計ジャッジ時間 | 5,612 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 22 RE * 8 | 
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()
using namespace std;
typedef long long ll;
const int MAX_N2 = (int)5e6 + 1;
int cnt1[MAX_N2];
int cnt2[MAX_N2];
	
int main()
{
	memset(cnt1, 0, sizeof(cnt1));
	memset(cnt2, 0, sizeof(cnt2));
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int N, D; cin >> N >> D;
	for (int x = 1; x <= N; ++x){
		for (int y = 1; y <= N; ++y){
			++cnt1[x*x + y*y];
		} // end for
	} // end for
	for (int w = 1; w <= N; ++w){
		for (int z = 1; z <= N; ++z){
			int i = w * w - z * z + D;
			if (i >= 0){
				++cnt2[i];
			} // end if
		} // end for
	} // end for
	ll res = 0LL;
	rep (i, MAX_N2){
		res += (ll)cnt1[i] * cnt2[i];
	} // end rep
	cout << res << endl;
	return 0;
}
            
            
            
        
            
ty70