結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
28,532 KB
testcase_01 AC 36 ms
28,512 KB
testcase_02 AC 31 ms
28,740 KB
testcase_03 AC 29 ms
28,608 KB
testcase_04 AC 31 ms
28,460 KB
testcase_05 AC 30 ms
28,472 KB
testcase_06 AC 32 ms
28,548 KB
testcase_07 AC 30 ms
28,508 KB
testcase_08 AC 28 ms
28,456 KB
testcase_09 AC 31 ms
28,744 KB
testcase_10 AC 31 ms
28,508 KB
testcase_11 AC 30 ms
28,596 KB
testcase_12 AC 31 ms
28,464 KB
testcase_13 AC 212 ms
34,604 KB
testcase_14 AC 204 ms
34,596 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 186 ms
34,592 KB
testcase_18 WA -
testcase_19 AC 120 ms
34,592 KB
testcase_20 AC 86 ms
31,352 KB
testcase_21 AC 42 ms
29,012 KB
testcase_22 AC 159 ms
34,912 KB
testcase_23 AC 206 ms
34,732 KB
testcase_24 AC 119 ms
32,716 KB
testcase_25 AC 51 ms
29,496 KB
testcase_26 AC 198 ms
34,720 KB
testcase_27 AC 211 ms
34,600 KB
testcase_28 AC 138 ms
33,360 KB
testcase_29 AC 97 ms
31,708 KB
testcase_30 WA -
testcase_31 AC 110 ms
32,544 KB
testcase_32 WA -
testcase_33 AC 184 ms
34,788 KB
testcase_34 WA -
権限があれば一括ダウンロードができます

ソースコード

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] -= cnt[i];
    }
    ll ans = 0;
    for(i=1;i<n;i++) ans += cnt[i];
    cout << ans << endl;
}
0