結果

問題 No.890 移調の限られた旋法
ユーザー totori_nyaatotori_nyaa
提出日時 2019-09-21 15:48:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 46 ms / 2,000 ms
コード長 1,452 bytes
コンパイル時間 1,691 ms
コンパイル使用メモリ 168,944 KB
実行使用メモリ 34,896 KB
最終ジャッジ日時 2023-10-19 03:58:34
合計ジャッジ時間 3,818 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
27,088 KB
testcase_01 AC 28 ms
27,088 KB
testcase_02 AC 28 ms
27,088 KB
testcase_03 AC 30 ms
27,088 KB
testcase_04 AC 27 ms
27,088 KB
testcase_05 AC 29 ms
27,088 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 30 ms
27,088 KB
testcase_08 AC 28 ms
27,088 KB
testcase_09 AC 27 ms
27,088 KB
testcase_10 AC 28 ms
27,088 KB
testcase_11 AC 27 ms
27,088 KB
testcase_12 AC 28 ms
27,088 KB
testcase_13 AC 6 ms
11,456 KB
testcase_14 AC 42 ms
34,896 KB
testcase_15 AC 43 ms
34,896 KB
testcase_16 AC 44 ms
34,896 KB
testcase_17 AC 42 ms
34,116 KB
testcase_18 AC 40 ms
34,116 KB
testcase_19 AC 35 ms
31,180 KB
testcase_20 AC 33 ms
29,700 KB
testcase_21 AC 29 ms
27,640 KB
testcase_22 AC 39 ms
33,068 KB
testcase_23 AC 44 ms
34,424 KB
testcase_24 AC 36 ms
31,280 KB
testcase_25 AC 30 ms
28,064 KB
testcase_26 AC 44 ms
34,576 KB
testcase_27 AC 43 ms
34,704 KB
testcase_28 AC 37 ms
31,976 KB
testcase_29 AC 36 ms
30,280 KB
testcase_30 AC 42 ms
34,124 KB
testcase_31 AC 35 ms
31,072 KB
testcase_32 AC 41 ms
33,584 KB
testcase_33 AC 5 ms
10,536 KB
testcase_34 AC 46 ms
33,976 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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


const int MAX = 1000010;
const int mod = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; 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 COM(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;
}

long long gcd(long long a, long long b){
    if(b==0) return a;
    return gcd(b,a%b);
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    ll n,k;

    cin>>n>>k;
    ll dp[n]={};
    ll g = gcd(n,k);
    if(n==k && k!=1){
        cout << 1 << endl;
        return 0;
    }
    COMinit();
    for(int i=1;i<n;i++){
        if(g%i) continue;
        dp[i] += COM(n/i,k/i);
    }
    ll ans = 0;
    for(int i=n-1;i>=2;i--){
        if(dp[i]==0) continue;
        //cerr << i<<" " << dp[i]<<endl;
        ans += dp[i];
        ans %= mod;
        for(int j=2;j*j<=i;j++){
            if(i%j) continue;
            dp[j] += mod - dp[i];
            dp[j] %= mod;
            if(j*j!=i) (dp[i/j] += mod - dp[i])%=mod;
        }
    }
    cout << ans << endl;


}
0