結果

問題 No.800 四平方定理
ユーザー ugis_prog
提出日時 2019-03-17 22:42:10
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 87 ms / 2,000 ms
コード長 484 bytes
コンパイル時間 527 ms
コンパイル使用メモリ 61,404 KB
実行使用メモリ 34,432 KB
最終ジャッジ日時 2024-07-08 00:56:21
合計ジャッジ時間 2,261 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
    long N,D;
    cin >> N >> D;
    vector<int> sq(2*N*N+1,0);

    for(int y=1;y<=N;y++){
        for(int z=1;z<=N;z++){
            sq[y*y+z*z]++;
        }
    }

    long ans = 0;
    for(long x=1;x<=N;x++){
        for(long w=1;w<=N;w++){
            long c = w*w - x*x + D;
            if(c < 2 || c > 2*N*N) continue;
            ans += sq[c];
        }
    }
    cout << ans << endl;
}
0