結果

問題 No.800 四平方定理
コンテスト
ユーザー vjudge1
提出日時 2026-03-10 18:42:57
言語 C++23
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 54 ms / 2,000 ms
コード長 835 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,033 ms
コンパイル使用メモリ 335,584 KB
実行使用メモリ 65,992 KB
最終ジャッジ日時 2026-03-10 18:43:03
合計ジャッジ時間 4,074 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
#define nl << '\n';

const ll N = 8e6 + 5, M = 1e9 + 7;

void solve(ll tc) {
    ll n, d;
    cin >> n >> d;
    vector<ll> m(N);
    for (ll i = 1; i <= n; i++) {
        for (ll j = 1; j <= n; j++) {
            if ((i * i) + (j * j) < N) {
                m[(i * i) + (j * j)]++;
            }
        }
    }
    ll c = 0;
    for (ll i = 1; i <= n; i++) {
        for (ll j = 1; j <= n; j++) {
            if ((i * i) - (j * j) + d >= 2) {
                c += m[(i * i) - (j * j) + d];
            }
        }
    }
    cout << c nl
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    ll t = 1;
    // cin >> t;
    for (ll i = 1; i <= t; i++) {
        solve(i);
    }
    return 0;
}
0