結果

問題 No.800 四平方定理
ユーザー nebukuro09
提出日時 2019-04-18 05:13:54
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,998 ms / 2,000 ms
コード長 580 bytes
コンパイル時間 1,787 ms
コンパイル使用メモリ 174,064 KB
実行使用メモリ 88,248 KB
最終ジャッジ日時 2024-09-22 08:45:00
合計ジャッジ時間 28,541 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);i++)
#define REP2(i,m,n) for (int i=m;i<(n);i++)
typedef long long ll;

ll N, D;

void solve() {
    cin >> N >> D;

    unordered_map<ll, ll> cnt;
    REP2 (z, 1, N+1) REP2 (w, 1, N+1) cnt[z*z-w*w] += 1;
    ll ans = 0;

    REP2 (x, 1, N+1) {
        REP2 (y, 1, N+1) {
            if (cnt.find(D-x*x-y*y) != cnt.end()) {
                ans += cnt[D-x*x-y*y];
            }
        }
    }

    cout << ans << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
}
0