結果

問題 No.890 移調の限られた旋法
ユーザー totori_nyaatotori_nyaa
提出日時 2019-09-20 22:56:56
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,576 bytes
コンパイル時間 1,549 ms
コンパイル使用メモリ 165,548 KB
実行使用メモリ 27,124 KB
最終ジャッジ日時 2023-10-12 20:52:12
合計ジャッジ時間 4,030 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
26,772 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 25 ms
26,772 KB
testcase_03 AC 25 ms
26,936 KB
testcase_04 AC 25 ms
26,908 KB
testcase_05 WA -
testcase_06 AC 26 ms
26,756 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 25 ms
26,908 KB
testcase_10 AC 1 ms
4,352 KB
testcase_11 AC 2 ms
4,352 KB
testcase_12 AC 25 ms
26,892 KB
testcase_13 AC 26 ms
26,840 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 25 ms
26,832 KB
testcase_20 AC 2 ms
4,352 KB
testcase_21 AC 1 ms
4,348 KB
testcase_22 AC 25 ms
27,008 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 25 ms
26,812 KB
testcase_25 AC 2 ms
4,352 KB
testcase_26 WA -
testcase_27 AC 24 ms
26,764 KB
testcase_28 AC 2 ms
4,352 KB
testcase_29 AC 24 ms
26,912 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 25 ms
26,840 KB
testcase_34 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

long long gcd(long long a, long long b){
    if(b==0) return a;
    return gcd(b,a%b);
}
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;
}

bool isprime(long long int val) {
    if (val <= 1)return false;
    for (long long int i = 2; i*i <= val; i++) {
        if (val%i == 0LL)return false;
    }
    return true;
}

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

    ll n,k;
    cin>>n>>k;
    ll g = gcd(n,k);
    if(k==1){
        cout << n << endl;
        return 0;
    }
    if(g==1){
        cout << 0 << endl;
        return 0;
    }
    COMinit();
    ll ans = 0;
    int cnt=0;
    for(ll i=1;i*i<=g;i++){
        if(g%i==0){
            if(isprime(i)) ans += COM(n/i,k/i),cnt++;
            ans %= mod;
            if(i*i!=g && isprime(g/i)) ans += COM(n/(g/i),k/(g/i)), cnt++;
            ans %= mod;
        }
    }
    ans -= (cnt-1)*COM(n/g,k/g);
    while(ans<0) ans+=mod;
    ans %= mod;
    cout << ans << endl;


}
0