結果

問題 No.152 貯金箱の消失
ユーザー okchan08okchan08
提出日時 2018-04-06 22:16:08
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 194 ms / 5,000 ms
コード長 598 bytes
コンパイル時間 405 ms
コンパイル使用メモリ 58,576 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-08 18:04:56
合計ジャッジ時間 3,702 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>

using namespace std;
using ll = unsigned long long;

const int MOD = 1e6+3;
const int MAX = 1e7;

ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b, a%b);
}

int main(){
    int L; cin >> L;

    int ans = 0;
    for(int i=1;i*i<=MAX; i++){
        for(int j=1; j<i && i*i + j*j < MAX;j++){
            if(i%2 == j%2) continue;
            if(gcd(i,j) > 1) continue;

            ll a = i*i - j*j;
            ll b = 2*i*j;
            ll c = i*i + j*j;
            if((a+b+c)*4 <= L) (ans += 1) %= MOD;
        }
    }
    cout << ans << endl;

}

0