結果

問題 No.800 四平方定理
ユーザー sten_san
提出日時 2021-02-13 12:19:25
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 96 ms / 2,000 ms
コード長 879 bytes
コンパイル時間 2,503 ms
コンパイル使用メモリ 191,376 KB
最終ジャッジ日時 2025-01-18 20:05:54
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

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

struct uns_t {} uns;
template <typename Element, typename Head, typename ...Args>
auto vec(Element init, Head arg, Args ...args) {
    if constexpr (sizeof...(Args) == 0) return std::vector(arg, init);
    else return std::vector(arg, vec(init, args...));
}
template <typename Element, typename Head, typename ...Args>
auto vec(uns_t, Head arg, Args ...args) {
    return vec(Element(), arg, args...);
}

array<int, 10000000> cnt;

int main() {
    int n, d; cin >> n >> d;

    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= n; ++j) {
            if (i * i - j * j + d < 0) continue;
            ++cnt[i * i - j * j + d];
        }
    }

    int64_t ans = 0;
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= n; ++j) {
            ans += cnt[i * i + j * j];
        }
    }

    cout << ans << endl;
}

0