結果

問題 No.890 移調の限られた旋法
ユーザー face4face4
提出日時 2019-09-21 09:53:53
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 19 ms / 2,000 ms
コード長 1,727 bytes
コンパイル時間 725 ms
コンパイル使用メモリ 73,756 KB
実行使用メモリ 19,092 KB
最終ジャッジ日時 2023-10-17 11:52:27
合計ジャッジ時間 2,387 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 19 ms
19,092 KB
testcase_14 AC 19 ms
19,092 KB
testcase_15 AC 19 ms
19,092 KB
testcase_16 AC 19 ms
19,092 KB
testcase_17 AC 17 ms
17,508 KB
testcase_18 AC 17 ms
17,508 KB
testcase_19 AC 12 ms
11,640 KB
testcase_20 AC 9 ms
8,608 KB
testcase_21 AC 3 ms
4,384 KB
testcase_22 AC 15 ms
15,200 KB
testcase_23 AC 18 ms
18,036 KB
testcase_24 AC 12 ms
11,640 KB
testcase_25 AC 5 ms
5,176 KB
testcase_26 AC 18 ms
18,312 KB
testcase_27 AC 19 ms
18,564 KB
testcase_28 AC 13 ms
13,156 KB
testcase_29 AC 10 ms
9,600 KB
testcase_30 AC 17 ms
17,508 KB
testcase_31 AC 12 ms
11,376 KB
testcase_32 AC 16 ms
16,256 KB
testcase_33 AC 16 ms
17,244 KB
testcase_34 AC 17 ms
17,244 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
using namespace std;

typedef long long ll;
const ll mod = 1e9 + 7;

ll modpow(ll a, ll b, ll p = 1e9+7){
    if(b == 0)  return 1;

    if(b % 2 == 0){
        ll d = modpow(a, b/2, p);
        return (d*d) % p;
    }else{
        return (a%p * modpow(a, b-1, p)) % p;
    }
}

struct ModComb{
    vector<ll> po, inv;
    ll N;

    ModComb(ll n) : N(n), po(n), inv(n) {
        po[0] = 1;
        for(int i = 1; i < N; i++)  po[i] = (po[i-1] * i) % mod;
        inv[N-1] = modpow(po[N-1], mod-2, mod);
        for(int i = N-2; i >= 0; i--)   inv[i] = (inv[i+1] * (i+1)) % mod;
    }
    
    ll nCk(ll n, ll k){
        if(k == 0)  return 1;
        if(n < k)   return 0;
        return (((po[n]*inv[n-k])%mod)*inv[k])%mod;
    }

    ll nPk(ll n, ll k){
        if(k == 0)  return 1;
        if(n < k)   return 0;
        return (po[n]*inv[n-k])%mod;
    }

    ll nHk(ll n, ll k){
        if(n == 0 && k == 0)    return 1;
        return nCk(n+k-1, k-1);
    }
};

ll gcd(ll a, ll b){
    return b == 0 ? a : gcd(b, a%b);
}

int main(){
    ll n, k;
    cin >> n >> k;
    vector<int> v;
    ll x = gcd(n, k);
    for(int i = 2; i*i <= x; i++){
        if(x%i == 0){
            v.push_back(i);
            while(x%i == 0) x /= i;
        }
    }
    if(x != 1)  v.push_back(x);
    ModComb mc(n+1);
    int siz = v.size();
    ll ans = 0;
    for(int i = 1; i < 1<<siz; i++){
        int tmp = 1, cnt = 0;
        for(int j = 0; j < siz; j++){
            if((i>>j)&1)    tmp *= v[j], cnt++;
        }
        ll x = cnt%2 == 0 ? -1 : 1;
        x *= mc.nCk(n/tmp, k/tmp);
        x = (x + mod) % mod;
        ans += x;
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}
0