結果

問題 No.2896 Monotonic Prime Factors
ユーザー 憩いの場憩いの場
提出日時 2024-09-20 22:06:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 422 ms / 2,000 ms
コード長 1,728 bytes
コンパイル時間 3,701 ms
コンパイル使用メモリ 261,972 KB
実行使用メモリ 45,568 KB
最終ジャッジ日時 2024-09-20 22:07:20
合計ジャッジ時間 10,130 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 168 ms
45,568 KB
testcase_01 AC 148 ms
45,492 KB
testcase_02 AC 145 ms
45,568 KB
testcase_03 AC 148 ms
45,532 KB
testcase_04 AC 422 ms
45,484 KB
testcase_05 AC 358 ms
45,552 KB
testcase_06 AC 338 ms
45,496 KB
testcase_07 AC 413 ms
45,492 KB
testcase_08 AC 417 ms
45,476 KB
testcase_09 AC 376 ms
45,556 KB
testcase_10 AC 253 ms
45,440 KB
testcase_11 AC 169 ms
45,484 KB
testcase_12 AC 154 ms
45,504 KB
testcase_13 AC 317 ms
45,476 KB
testcase_14 AC 303 ms
45,476 KB
testcase_15 AC 151 ms
45,496 KB
testcase_16 AC 193 ms
45,544 KB
testcase_17 AC 173 ms
45,568 KB
testcase_18 AC 387 ms
45,516 KB
testcase_19 AC 171 ms
45,476 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/all>

using namespace std;
using namespace atcoder;

#include<vector>

class CombinationMod
{
public :
    CombinationMod() = default;
    CombinationMod( int max_size, int mod ) : MAX_SIZE( max_size ),
                                              MOD( mod ),
                                              fac( max_size, 1 ),
                                              finv( max_size, 1 ),
                                              inv( max_size, 1 )
    {
        for ( int i = 2; i < MAX_SIZE; i++ )
        {
            fac[i] = fac[i - 1] * i % MOD;
            inv[i] = MOD - inv[ MOD % i] * ( MOD / i ) % MOD;
            finv[i] = finv[i - 1] * inv[i] % MOD;
        }
    }

    long long calculateCombination( int n, int k )
    {
        if( n < k ) return 0;
        if( n < 0 || k < 0 ) return 0;

        return fac[n] * ( finv[k] * finv[n - k] % MOD ) % MOD;
    }

    int getMaxSize( void ) { return MAX_SIZE; }
    int getMod( void ) { return MOD; }

private :
    int MAX_SIZE, MOD;
    std::vector<long long> fac;
    std::vector<long long> finv;
    std::vector<long long> inv;
};

int main( void )
{
    CombinationMod com( 1800000, 998244353 );

    int Q;
    cin >> Q;

    int cur = 0;
    int A, B;
    while( Q-- > 0 )
    {
        cin >> A >> B;
        for( int i = 2; i * i <= A; i++ )
        {
            while( A % i == 0 )
            {
                A /= i;
                cur++;
            }
        }
        if( A != 1 ) cur++;

        if( cur < B )
        {
            cout << 0 << endl;
        }
        else
        {
            cout << com.calculateCombination( cur - 1, B - 1 ) << endl;
        }
    }
    

    return 0;
}
0