結果
| 問題 | 
                            No.800 四平方定理
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2019-03-17 21:33:41 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 1,312 ms / 2,000 ms | 
| コード長 | 634 bytes | 
| コンパイル時間 | 1,858 ms | 
| コンパイル使用メモリ | 197,904 KB | 
| 最終ジャッジ日時 | 2025-01-06 22:46:19 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 30 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout.precision(12);
    cout.setf(ios_base::fixed, ios_base::floatfield);
    
    int n, d;
    cin >> n >> d;
    vector<int> xy, zw;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            xy.push_back(i*i+j*j);
            zw.push_back(i*i-j*j);
        }
    }
    sort(zw.begin(), zw.end());
    uint64_t ans = 0;
    for(auto lhs:xy){
        ans += distance(lower_bound(zw.begin(), zw.end(), lhs-d), upper_bound(zw.begin(), zw.end(), lhs-d));
    } 
    cout << ans << endl;
    return 0;
}