結果

問題 No.152 貯金箱の消失
ユーザー HachimoriHachimori
提出日時 2015-02-16 00:38:29
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 29 ms / 5,000 ms
コード長 708 bytes
コンパイル時間 476 ms
コンパイル使用メモリ 52,932 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-06 01:32:44
合計ジャッジ時間 1,367 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 6 ms
4,380 KB
testcase_08 AC 28 ms
4,376 KB
testcase_09 AC 29 ms
4,376 KB
testcase_10 AC 22 ms
4,380 KB
testcase_11 AC 13 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
using namespace std;

int N;

void read() {
    cin >> N;
}


int gcd(int a, int b) {
    return b == 0 ? a : gcd(b, a % b);
}


void work() {
    int ans = 0;
    
    for (int m = 1; m * m <= N; ++m)
        for (int n = 1; n < m && m * m + n * n <= N; ++n) {
            if (gcd(m, n) != 1)
                continue;

            if (m % 2 == n % 2)
                continue;
            
            int a = m * m - n * n;
            int b = 2 * m * n;
            int c = m * m + n * n;

            if (4 * (a + b + c) > N)
                break;
            
            ++ans;
        }

    cout << ans % 1000003 << endl;
}


int main() {
    read();
    work();
    return 0;
}
0