結果

問題 No.2120 場合の数の下8桁
ユーザー 259_Momone259_Momone
提出日時 2022-11-04 22:19:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,421 bytes
コンパイル時間 3,287 ms
コンパイル使用メモリ 257,620 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-26 00:47:34
合計ジャッジ時間 5,185 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/extc++.h>

int main() {
    using namespace std;
    unsigned long M, N;
    cin >> M >> N;
    unsigned long value{1}, ord_2{}, ord_5{};
    if(N > M){
        cout << 0 << endl;
        return 0;
    }
    if(2 * N > M)N = M - N;
    const auto multiplies{[&value, &ord_2, &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) %= 100000000;
    }};
    const auto divides{[&value, &ord_2, &ord_5](unsigned long x){
        while(x && x % 2 == 0){
            --ord_2;
            x /= 2;
        }
        while(x && x % 5 == 0){
            --ord_5;
            x /= 5;
        }
        (value *= [](unsigned long a, unsigned long n){
            unsigned long r{1};
            while(n){
                if(n & 1)(r *= a) %= 100000000;
                (a *= a) %= 100000000;
                n /= 2;
            }
            return r;
        }(x, 4999999)) %= 100000000;
    }};
    for(unsigned long i{}; i < N; ++i){
        multiplies(M - i);
        divides(i + 1);
    }
    ord_2 = min(ord_2, 10UL);
    ord_5 = min(ord_5, 10UL);
    while(ord_2 > 0){
        --ord_2;
        (value *= 2) %= 100000000;
    }
    while(ord_5 > 0){
        --ord_5;
        (value *= 5) %= 100000000;
    }
    printf("%08lu\n", value);
    return 0;
}
0