結果

問題 No.2120 場合の数の下8桁
ユーザー 259_Momone259_Momone
提出日時 2022-11-04 22:28:25
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 229 ms / 2,000 ms
コード長 1,361 bytes
コンパイル時間 2,994 ms
コンパイル使用メモリ 256,968 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-26 00:58:13
合計ジャッジ時間 5,009 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 229 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 68 ms
4,376 KB
testcase_16 AC 224 ms
4,380 KB
testcase_17 AC 115 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 118 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/extc++.h>

int main() {
    using namespace std;
    constexpr unsigned long mod{100000000};
    unsigned long M, N;
    cin >> M >> N;
    unsigned long value_p{1}, ord_2_p{}, ord_5_p{};
    unsigned long value_m{1}, ord_2_m{}, ord_5_m{};
    if(N > M){
        printf("%08lu\n", 0UL);
        return 0;
    }
    const auto multiplies{[](unsigned long& value, unsigned long& ord_2, unsigned long& ord_5, unsigned long x){
        while(x && x % 2 == 0){
            ++ord_2;
            x /= 2;
        }
        while(x && x % 5 == 0){
            ++ord_5;
            x /= 5;
        }
        (value *= x) %= mod;
    }};
    for(unsigned long i{}; i < N; ++i){
        multiplies(value_p, ord_2_p, ord_5_p, M - i);
        multiplies(value_m, ord_2_m, ord_5_m, i + 1);
    }
    assert(ord_2_p >= ord_2_m);
    assert(ord_5_p >= ord_5_m);
    auto ord_2{ord_2_p - ord_2_m};
    auto ord_5{ord_5_p - ord_5_m};
    auto value{[](unsigned long a, unsigned long n, unsigned long b){
        while(n){
            if(n & 1)(b *= a) %= mod;
            (a *= a) %= mod;
            n /= 2;
        }
        return b;
    }(value_m, 4999999, value_p)};
    while(ord_2 > 0){
        --ord_2;
        (value *= 2) %= mod;
    }
    while(ord_5 > 0){
        --ord_5;
        (value *= 5) %= mod;
    }
    printf("%08lu\n", value);
    return 0;
}
0