結果

問題 No.890 移調の限られた旋法
ユーザー pockynypockyny
提出日時 2021-12-18 03:39:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 249 ms / 2,000 ms
コード長 1,078 bytes
コンパイル時間 656 ms
コンパイル使用メモリ 70,020 KB
実行使用メモリ 34,888 KB
最終ジャッジ日時 2023-10-13 07:44:15
合計ジャッジ時間 6,584 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
28,468 KB
testcase_01 AC 33 ms
28,468 KB
testcase_02 AC 32 ms
28,612 KB
testcase_03 AC 34 ms
28,552 KB
testcase_04 AC 35 ms
28,468 KB
testcase_05 AC 34 ms
28,672 KB
testcase_06 AC 33 ms
28,484 KB
testcase_07 AC 33 ms
28,556 KB
testcase_08 AC 32 ms
28,464 KB
testcase_09 AC 31 ms
28,460 KB
testcase_10 AC 32 ms
28,576 KB
testcase_11 AC 31 ms
28,464 KB
testcase_12 AC 31 ms
28,472 KB
testcase_13 AC 244 ms
34,592 KB
testcase_14 AC 245 ms
34,596 KB
testcase_15 AC 238 ms
34,588 KB
testcase_16 AC 249 ms
34,596 KB
testcase_17 AC 214 ms
34,592 KB
testcase_18 AC 212 ms
34,808 KB
testcase_19 AC 130 ms
34,592 KB
testcase_20 AC 94 ms
31,084 KB
testcase_21 AC 44 ms
29,064 KB
testcase_22 AC 181 ms
34,676 KB
testcase_23 AC 234 ms
34,888 KB
testcase_24 AC 133 ms
32,668 KB
testcase_25 AC 51 ms
29,452 KB
testcase_26 AC 226 ms
34,680 KB
testcase_27 AC 238 ms
34,604 KB
testcase_28 AC 154 ms
33,372 KB
testcase_29 AC 106 ms
31,808 KB
testcase_30 AC 201 ms
34,596 KB
testcase_31 AC 125 ms
32,552 KB
testcase_32 AC 195 ms
34,728 KB
testcase_33 AC 218 ms
34,600 KB
testcase_34 AC 201 ms
34,744 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>

using namespace std;
using ll = long long;
const int MX = 1000100;
ll f[MX],inv[MX],fi[MX];
constexpr ll mod = 1000000007;
void solve(){
    inv[1] = 1;
    for(int i=2;i<MX;i++){
        inv[i] = mod - (mod/i)*inv[mod%i]%mod;
    }
    f[0] = fi[0] = 1;
    for(int i=1;i<MX;i++){
        f[i] = f[i-1]*i%mod;
        fi[i] = fi[i-1]*inv[i]%mod;
    }
}

ll nck(ll n, ll k){
    if(n<0 || k<0 || n<k) return 0;
    return f[n]*fi[k]%mod*fi[n-k]%mod;
}

ll pw(ll a,ll x){
    ll ret = 1;
    while(x){
        if(x&1) (ret *= a) %= mod;
        (a *= a) %= mod; x /= 2;
    }
    return ret;
}

int gcd(int x,int y){
    if(x<y) swap(x,y);
    if(y==0) return x;
    return gcd(x%y,y);
}

ll cnt[1000010];
int main(){
    int i,j,n,k; cin >> n >> k;
    solve();
    for(i=1;i<n;i++){
        int x = n/gcd(i,n);
        if(k%x!=0) continue;
        cnt[i] = nck(n/x,k/x);
    }
    for(i=1;i<=n;i++){
        for(j=2*i;j<=n;j+=i) (cnt[j] += mod - cnt[i]) %= mod;
    }
    ll ans = 0;
    for(i=1;i<n;i++) (ans += cnt[i]) %= mod;
    cout << ans << endl;
}
0