結果
| 問題 | 
                            No.800 四平方定理
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2020-10-15 21:24:41 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 163 ms / 2,000 ms | 
| コード長 | 891 bytes | 
| コンパイル時間 | 1,714 ms | 
| コンパイル使用メモリ | 168,268 KB | 
| 実行使用メモリ | 64,512 KB | 
| 最終ジャッジ日時 | 2024-07-20 19:57:00 | 
| 合計ジャッジ時間 | 5,083 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 30 | 
ソースコード
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ld long double
#define INF 1000000000000000000
typedef pair<ll, ll> pll;
typedef pair<int, int> pint;
ll cnt[100000000] = {0};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, D;
    cin >> N >> D;
    ll ans = 0;
    map<ll, ll> ma;
    for (int x = 1; x <= N; x++) {
        for (int y = 1; y <= N; y++) {
            ll tmp = x * x + y * y;
            if (tmp > 100000000)
                continue;
            cnt[tmp]++;
        }
    }
    for (int w = 1; w <= N; w++) {
        for (int z = 1; z <= N; z++) {
            int tmp = w * w - z * z + D;
            if (tmp >= 0 && cnt[tmp] > 0)
                ans += cnt[tmp];
        }
    }
    cout << ans << endl;
}