結果

問題 No.800 四平方定理
コンテスト
ユーザー vjudge1
提出日時 2026-03-10 18:28:12
言語 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  
実行時間 47 ms / 2,000 ms
コード長 959 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,149 ms
コンパイル使用メモリ 333,528 KB
実行使用メモリ 67,864 KB
最終ジャッジ日時 2026-03-10 18:28:16
合計ジャッジ時間 3,801 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail>
void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#define dbg(...) cerr << "(" << #__VA_ARGS__ << ")", dbg_out(__VA_ARGS__)

#define int long long

const int MOD = 1e9 + 7;
const int INF = LLONG_MAX >> 1;

const int N = 4000000, M = 9e6;

int cnt[M];

void solve() {
    int n, d; cin >> n >> d;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            cnt[i * i - j * j + N]++;
        }
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            int t = d - i * i - j * j + N;
            if (0 <= t && t < M) {
                ans += cnt[t];
            }
        }
    }
    cout << ans << '\n';
}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int tc = 1;
    // cin >> tc;

    while (tc--)  solve();
}
0