結果

問題 No.890 移調の限られた旋法
ユーザー ゆきのんゆきのん
提出日時 2019-09-20 23:13:14
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,068 bytes
コンパイル時間 1,748 ms
コンパイル使用メモリ 153,072 KB
実行使用メモリ 36,636 KB
最終ジャッジ日時 2023-10-12 21:42:36
合計ジャッジ時間 4,772 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
36,172 KB
testcase_01 AC 44 ms
35,304 KB
testcase_02 AC 45 ms
36,024 KB
testcase_03 AC 43 ms
35,616 KB
testcase_04 AC 45 ms
36,208 KB
testcase_05 WA -
testcase_06 AC 7 ms
18,612 KB
testcase_07 AC 44 ms
35,720 KB
testcase_08 AC 44 ms
35,692 KB
testcase_09 AC 44 ms
35,956 KB
testcase_10 AC 43 ms
35,236 KB
testcase_11 AC 44 ms
35,968 KB
testcase_12 AC 44 ms
35,272 KB
testcase_13 AC 7 ms
18,676 KB
testcase_14 AC 45 ms
35,912 KB
testcase_15 AC 44 ms
35,612 KB
testcase_16 AC 45 ms
36,276 KB
testcase_17 AC 44 ms
36,064 KB
testcase_18 AC 44 ms
35,716 KB
testcase_19 AC 45 ms
36,184 KB
testcase_20 AC 45 ms
35,368 KB
testcase_21 AC 46 ms
36,544 KB
testcase_22 AC 45 ms
35,696 KB
testcase_23 AC 44 ms
36,352 KB
testcase_24 AC 44 ms
35,496 KB
testcase_25 AC 45 ms
36,192 KB
testcase_26 AC 47 ms
36,636 KB
testcase_27 AC 45 ms
36,128 KB
testcase_28 AC 46 ms
36,244 KB
testcase_29 AC 45 ms
35,744 KB
testcase_30 AC 44 ms
35,820 KB
testcase_31 AC 45 ms
35,568 KB
testcase_32 AC 44 ms
35,236 KB
testcase_33 AC 7 ms
18,600 KB
testcase_34 AC 44 ms
35,512 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;
    if(n==k){
        puts("1");
        return 0;
    }
    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