結果

問題 No.129 お年玉(2)
ユーザー krotonkroton
提出日時 2015-01-16 23:03:41
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,233 bytes
コンパイル時間 2,339 ms
コンパイル使用メモリ 149,072 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-18 16:22:45
合計ジャッジ時間 3,387 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 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 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 1 ms
4,376 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 1 ms
4,380 KB
testcase_38 AC 2 ms
4,376 KB
testcase_39 AC 2 ms
4,380 KB
testcase_40 AC 1 ms
4,376 KB
testcase_41 AC 2 ms
4,376 KB
testcase_42 AC 2 ms
4,376 KB
testcase_43 AC 2 ms
4,380 KB
testcase_44 AC 2 ms
4,380 KB
testcase_45 AC 2 ms
4,376 KB
testcase_46 AC 2 ms
4,376 KB
testcase_47 AC 1 ms
4,376 KB
testcase_48 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef tuple<ll, int, int> Tp;

const ll MOD = 1e9;

ll mod_pow(ll x, ll e){
    ll v = 1;
    for(;e;e>>=1){
        if(e & 1)
            v = (v * x) % MOD;
        x = (x * x) % MOD;
    }
    return v;
}

ll inverse(ll a, ll m){
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        swap(a -= t * b, b);
        swap(u -= t * v, v);
    }
    return (u % m + m) % m;
}

Tp calc(int a, int b){
    ll rem = 1;
    int two = 0, five = 0;
    
    for(int i=a;i<=b;i++){
        int j = i;
        while(j % 2 == 0){
            ++two;
            j /= 2;
        }
        while(j % 5 == 0){
            ++five;
            j /= 5;
        }
        rem = (rem * j) % MOD;
    }
    
    return Tp(rem, two, five);
}

int main(){
    ll N, M;
    cin >> N >> M;
    
    N /= 1000;
    N %= M;
    
    auto num = calc(M - N + 1, M);
    auto den = calc(1, N);
    
    int two = get<1>(num) - get<1>(den);
    int five = get<2>(num) - get<2>(den);
    
    ll res = get<0>(num) * inverse(get<0>(den), MOD) % MOD;
    res = (res * mod_pow(2, two)) % MOD;
    res = (res * mod_pow(5, five)) % MOD;
    
    cout << res << endl;
    return 0;
}
0