結果
| 問題 | 
                            No.800 四平方定理
                             | 
                    
| コンテスト | |
| ユーザー | 
                             t33f
                         | 
                    
| 提出日時 | 2019-03-17 22:47:46 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 51 ms / 2,000 ms | 
| コード長 | 535 bytes | 
| コンパイル時間 | 716 ms | 
| コンパイル使用メモリ | 75,512 KB | 
| 実行使用メモリ | 38,528 KB | 
| 最終ジャッジ日時 | 2024-07-08 01:10:49 | 
| 合計ジャッジ時間 | 2,445 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 30 | 
ソースコード
#include <cmath>
#include <vector>
#include <iostream>
using namespace std;
int main() {
    int n, D; cin >> n >> D;
    constexpr int N = 9'000'001;
    vector<int> div(N, 0);
    for (int d = 1; d <= n; d++)
        for (int m = d+2; m <= 2*n - d && m * d < N; m += 2)
            div[m*d]++;
    long long ans = 0;
    for (int x = 1; x <= n; x++)
        for (int y = 1; y <= n; y++) {
            int v = abs(x*x + y*y - D);
            if (v == 0) ans += n;
            else ans += div[v];
        }
    cout << ans << endl;
}
            
            
            
        
            
t33f