結果
| 問題 | 
                            No.800 四平方定理
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2019-03-17 21:26:28 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 54 ms / 2,000 ms | 
| コード長 | 971 bytes | 
| コンパイル時間 | 989 ms | 
| コンパイル使用メモリ | 117,196 KB | 
| 実行使用メモリ | 34,556 KB | 
| 最終ジャッジ日時 | 2024-07-07 20:18:42 | 
| 合計ジャッジ時間 | 2,412 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 30 | 
ソースコード
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;
int main()
{
    int n, d;
    cin >> n>> d;
    vector<int> cnt(n*n*2+1, 0);
    for(int x=1; x<=n; ++x){
        for(int y=1; y<=n; ++y){
            int i = x * x + y * y;
            ++ cnt[i];
        }
    }
    long long ans = 0;
    for(int z=1; z<=n; ++z){
        for(int w=1; w<=n; ++w){
            int i = d + w * w - z * z;
            if(0 <= i && i <= n * n * 2)
                ans += cnt[i];
        }
    }
    cout << ans << endl;
    return 0;
}