結果

問題 No.890 移調の限られた旋法
ユーザー potoooooooopotoooooooo
提出日時 2019-09-20 22:27:18
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 58 ms / 2,000 ms
コード長 1,570 bytes
コンパイル時間 1,595 ms
コンパイル使用メモリ 167,456 KB
実行使用メモリ 50,560 KB
最終ジャッジ日時 2023-10-12 19:57:02
合計ジャッジ時間 4,781 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
50,212 KB
testcase_01 AC 49 ms
50,228 KB
testcase_02 AC 51 ms
50,236 KB
testcase_03 AC 52 ms
50,232 KB
testcase_04 AC 49 ms
50,356 KB
testcase_05 AC 50 ms
50,228 KB
testcase_06 AC 51 ms
50,288 KB
testcase_07 AC 50 ms
50,312 KB
testcase_08 AC 53 ms
50,356 KB
testcase_09 AC 49 ms
50,220 KB
testcase_10 AC 49 ms
50,208 KB
testcase_11 AC 51 ms
50,264 KB
testcase_12 AC 52 ms
50,420 KB
testcase_13 AC 49 ms
50,228 KB
testcase_14 AC 51 ms
50,404 KB
testcase_15 AC 51 ms
50,292 KB
testcase_16 AC 52 ms
50,356 KB
testcase_17 AC 52 ms
50,212 KB
testcase_18 AC 53 ms
50,284 KB
testcase_19 AC 50 ms
50,560 KB
testcase_20 AC 53 ms
50,360 KB
testcase_21 AC 51 ms
50,240 KB
testcase_22 AC 52 ms
50,216 KB
testcase_23 AC 54 ms
50,412 KB
testcase_24 AC 49 ms
50,216 KB
testcase_25 AC 50 ms
50,360 KB
testcase_26 AC 51 ms
50,216 KB
testcase_27 AC 53 ms
50,288 KB
testcase_28 AC 52 ms
50,228 KB
testcase_29 AC 58 ms
50,300 KB
testcase_30 AC 53 ms
50,228 KB
testcase_31 AC 52 ms
50,240 KB
testcase_32 AC 52 ms
50,276 KB
testcase_33 AC 52 ms
50,232 KB
testcase_34 AC 52 ms
50,220 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define mod 1000000007
#define MAX_N 2000010
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