結果

問題 No.152 貯金箱の消失
ユーザー maine_honzukimaine_honzuki
提出日時 2020-05-27 00:00:53
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 139 ms / 5,000 ms
コード長 745 bytes
コンパイル時間 1,983 ms
コンパイル使用メモリ 168,944 KB
実行使用メモリ 11,648 KB
最終ジャッジ日時 2024-04-21 04:42:45
合計ジャッジ時間 2,592 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 3 ms
6,940 KB
testcase_06 AC 4 ms
6,944 KB
testcase_07 AC 18 ms
6,940 KB
testcase_08 AC 134 ms
11,648 KB
testcase_09 AC 139 ms
11,648 KB
testcase_10 AC 105 ms
9,984 KB
testcase_11 AC 52 ms
7,040 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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