結果

問題 No.890 移調の限られた旋法
ユーザー potoooooooopotoooooooo
提出日時 2019-09-20 22:26:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,569 bytes
コンパイル時間 1,681 ms
コンパイル使用メモリ 168,128 KB
実行使用メモリ 8,288 KB
最終ジャッジ日時 2023-10-12 19:55:57
合計ジャッジ時間 5,428 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
7,988 KB
testcase_01 AC 6 ms
8,024 KB
testcase_02 AC 6 ms
8,076 KB
testcase_03 AC 6 ms
7,980 KB
testcase_04 AC 6 ms
8,176 KB
testcase_05 AC 6 ms
7,980 KB
testcase_06 AC 6 ms
7,980 KB
testcase_07 AC 6 ms
8,080 KB
testcase_08 AC 6 ms
7,988 KB
testcase_09 AC 7 ms
8,208 KB
testcase_10 AC 6 ms
8,216 KB
testcase_11 AC 7 ms
8,036 KB
testcase_12 AC 6 ms
8,028 KB
testcase_13 RE -
testcase_14 AC 7 ms
8,036 KB
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 WA -
testcase_20 AC 6 ms
7,992 KB
testcase_21 AC 6 ms
8,052 KB
testcase_22 WA -
testcase_23 AC 6 ms
7,984 KB
testcase_24 WA -
testcase_25 AC 6 ms
8,052 KB
testcase_26 RE -
testcase_27 AC 6 ms
8,088 KB
testcase_28 AC 6 ms
8,092 KB
testcase_29 WA -
testcase_30 RE -
testcase_31 AC 6 ms
8,120 KB
testcase_32 RE -
testcase_33 RE -
testcase_34 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define mod 1000000007
#define MAX_N 200010
long long inv[MAX_N];
long long factorial[MAX_N];
long long inv_factorial[MAX_N];

void GetInv(){
    for (int i = 1; i < MAX_N; i++) {
        if (i == 1) inv[i] = 1;
        else {
            inv[i] = (mod - (mod / i) * inv[mod % i]) % mod;
            if (inv[i] < 0) inv[i] += mod;
        }
    }
}
void GetFactorial(){
    factorial[0] = 1; inv_factorial[0] = 1;
    for (int i = 1; i < MAX_N; i++) {
        factorial[i] = factorial[i-1] * i;
        factorial[i] %= mod;
        inv_factorial[i] = inv_factorial[i-1] * inv[i];
        inv_factorial[i] %= mod;
    }
}

long long combination(int n, int r) {
    long long ret = factorial[n] * inv_factorial[r];
    ret %= mod;
    ret *= inv_factorial[n-r];
    return ret % mod;
}

int main() {
    GetInv(); GetFactorial();
    int n, k; cin >> n >> k;
    int t = k;
    vector<int> v;
    for (int i = 2; i <= t; i++) {
        if (t % i == 0) {
            while (t % i == 0) {
                t /= i;
            }
            if (n % i == 0) v.emplace_back(i);
        }
    }
    long long ans = 0;
    int size = v.size();
    for (int i = 1; i < (1 << size); i++) {
        int cnt = 0;
        int r = 1;
        for (int k = 0; k < size; k++) {
            if (i & (1 << k)) {
                cnt++; r *= v[k];
            }
        }
        long long tmp = combination(n / r, k / r);
        if (cnt % 2 == 0) tmp = mod - tmp;
        ans = (ans + tmp) % mod;
    }
    cout << ans << endl;
    return 0;
}
0