結果

問題 No.890 移調の限られた旋法
ユーザー ゆきのん
提出日時 2019-09-20 23:14:11
言語 C++14
(gcc 9.2.0)
結果
AC  
実行時間 64 ms
コード長 2,011 Byte
コンパイル時間 1,524 ms
使用メモリ 35,088 KB
最終ジャッジ日時 2020-01-28 02:50:50

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
0_sample01.txt AC 64 ms
35,076 KB
0_sample02.txt AC 60 ms
35,076 KB
0_sample03.txt AC 64 ms
34,948 KB
1_small01.txt AC 60 ms
34,992 KB
1_small02.txt AC 60 ms
34,944 KB
1_small03.txt AC 64 ms
34,980 KB
1_small04.txt AC 60 ms
34,948 KB
1_small05.txt AC 64 ms
34,988 KB
1_small06.txt AC 60 ms
35,000 KB
1_small07.txt AC 64 ms
34,972 KB
1_small08.txt AC 60 ms
34,956 KB
1_small09.txt AC 64 ms
34,988 KB
1_small10.txt AC 60 ms
34,992 KB
2_large01.txt AC 64 ms
34,944 KB
2_large02.txt AC 60 ms
35,080 KB
2_large03.txt AC 64 ms
35,028 KB
2_large04.txt AC 60 ms
35,080 KB
2_large05.txt AC 64 ms
35,000 KB
2_large06.txt AC 60 ms
34,948 KB
2_large07.txt AC 64 ms
34,984 KB
2_large08.txt AC 64 ms
34,996 KB
2_large09.txt AC 60 ms
35,072 KB
2_large10.txt AC 64 ms
35,088 KB
2_large11.txt AC 60 ms
34,944 KB
2_large12.txt AC 60 ms
34,948 KB
2_large13.txt AC 64 ms
34,952 KB
2_large14.txt AC 64 ms
34,988 KB
2_large15.txt AC 60 ms
34,900 KB
2_large16.txt AC 64 ms
35,032 KB
2_large17.txt AC 60 ms
35,028 KB
2_large18.txt AC 60 ms
35,080 KB
2_large19.txt AC 64 ms
34,996 KB
2_large20.txt AC 60 ms
35,084 KB
2_large21.txt AC 60 ms
34,988 KB
2_large22.txt AC 64 ms
35,084 KB
テストケース一括ダウンロード

ソースコード

diff #
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;

vector<LL> fact;
vector<LL> inver(2000001);
 
LL combi(int n,int r){
    if(n<r||n<0||r<0) return 0;
    return fact[n]%mod*inver[n-r]%mod*inver[r]%mod;
}
 
 
LL fpow(LL a, LL n){
    LL x = 1;
    while(n > 0){
        if(n&1){
            x=x*a%mod;
        }
        a=a*a%mod;
        n >>= 1;
    }
    return x;
}
 
void set_combi(){
    LL s=1;
    fact.push_back(1);
    for(int i=1;i<=2000000;i++){
        s*=i;
        s%=mod;
        fact.push_back(s);
    }
    inver[2000000]=fpow(fact[2000000],mod-2);
    for(int i=1999999;i>=0;i--){
        inver[i]=inver[i+1]*(i+1)%mod;
    }
}

vector<LL> divi(LL K){
    vector<LL> v;
    for(int i=1;i*i<=K;i++){
        if(K%i) continue;
        v.pb(i);
        v.pb(K/i);
    }
    sort(ALL(v));
    v.erase(unique(ALL(v)),v.end());
    return v;
}

LL gcd(LL a,LL b){
    if(b>a) swap(a,b);
    if(a%b==0) return b;
    return gcd(b,a%b);
}
vector<LL> pdivi(LL K){
    vector<LL> v;
    for(int i=2;i*i<=K;i++){
        if(K%i) continue;
        v.pb(i);
        while(K%i==0){
            K/=i;
        }
    }
    if(K!=1) v.pb(K);
    return v;
}


int main(){
    LL n,k;cin >> n >> k;
    set_combi();
    LL a = gcd(n,k);
    auto p = pdivi(a);
    LL ans = 0;
    for (int i = 1; i < (1<<p.size()); i++) {
        int count = 0;
        LL s=n,t=k;
        for (int j = 0; j < p.size(); j++) {
            if(i>>j&1){
                count++;
                s/=p[j];
                t/=p[j];
            }
        }
        if(count%2){
            ans = (ans + combi(s,t)) % mod;
        }
        else{
            ans = (ans - combi(s,t) + mod) % mod;
        }
    }
    cout << ans << endl;
    return 0;
}
0