結果

問題 No.152 貯金箱の消失
コンテスト
ユーザー maine_honzuki
提出日時 2020-05-27 00:00:53
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 84 ms / 5,000 ms
コード長 745 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,001 ms
コンパイル使用メモリ 186,048 KB
実行使用メモリ 11,776 KB
最終ジャッジ日時 2026-04-30 09:40:27
合計ジャッジ時間 2,272 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
int mod = 1000003;

int gcd(int a, int b) {
    while (b) {
        int c = b;
        b = a % b;
        a = c;
    }
    return a;
}

int main() {
    int L;
    cin >> L;
    L /= 4;

    set<pair<int, int>> S;
    int ans = 0;
    for (int i = 1; i * i < L; i++) {
        for (int j = i + 1; j * j < L; j++) {
            int x = j * j - i * i;
            int y = j * j + i * i;
            int z = 2 * i * j;
            if (x + y + z > L)
                continue;
            if (gcd(x, y) != 1)
                continue;
            if (S.count({x, y}))
                continue;
            S.insert({x, y});
            ans++;
        }
    }

    ans %= mod;
    cout << ans << endl;
}
0