結果

問題 No.890 移調の限られた旋法
ユーザー ttttan2ttttan2
提出日時 2019-09-20 22:02:00
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 2,734 bytes
コンパイル時間 2,180 ms
コンパイル使用メモリ 148,796 KB
実行使用メモリ 6,968 KB
最終ジャッジ日時 2023-10-12 19:10:02
合計ジャッジ時間 8,050 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
5,140 KB
testcase_01 AC 9 ms
5,056 KB
testcase_02 AC 12 ms
5,136 KB
testcase_03 AC 10 ms
5,072 KB
testcase_04 AC 11 ms
5,008 KB
testcase_05 AC 10 ms
5,196 KB
testcase_06 AC 10 ms
5,004 KB
testcase_07 AC 10 ms
5,060 KB
testcase_08 AC 9 ms
5,020 KB
testcase_09 AC 11 ms
5,000 KB
testcase_10 AC 10 ms
5,148 KB
testcase_11 AC 9 ms
5,144 KB
testcase_12 AC 11 ms
5,216 KB
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 AC 14 ms
6,112 KB
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 AC 16 ms
6,968 KB
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
//ios::sync_with_stdio(false);
//cin.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll gya[200010];
ll kai[200010];
ll beki(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k%2==1){
            ret*=now;
            ret%=mod;
        }
        now*=now;
        now%=mod;
        k/=2;
    }
    return ret;
}
ll gyaku(ll n){
    return beki(n,mod-2);
}
void nckinit(ll n){
    kai[0]=1;
    kai[1]=1;
    for(int i=2;i<=n;i++){
        kai[i]=kai[i-1]*i;
        kai[i]%=mod;
    }
    gya[n]=gyaku(kai[n]);
    for(int i=n-1;i>=1;i--){
        gya[i]=gya[i+1]*(i+1);
        gya[i]%=mod;
    }
    gya[0]=1;
}
ll nck(ll n,ll k){
    if(k<0)return 0;
    if(k==0||n==k)return 1;
    ll ret=kai[n];
    ret*=gya[n-k];
    ret%=mod;
    ret*=gya[k];
    ret%=mod;
    return ret;
}
ll npk(ll n,ll k){
    if(k<0)return 0;
    if(k==0)return 1;
    ll ret=kai[n];
    ret*=gya[n-k];
    ret%=mod;
    return ret;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,k;cin>>n>>k;
    vector<ll> v;
    rep(i,2,n+1){
        if(n%i==0)v.push_back(i);
    }
    nckinit(n+10);
    ll ans=0;
    vector<ll> pri;
    bool used[1000001];
    fill(used,used+1000001,false);
    rep(i,2,1000001){
        if(used[i])continue;
        pri.push_back(i);
        for(ll j=i;j<=1000000;j+=i)used[j]=true;
    }
    rep(i,0,v.size()){
        ll now=v[i];
        if(k%now!=0)continue;
        ll u=now;
        ll cnt=0;
        rep(j,0,pri.size()){
            ll t=pri[j];
            if(u%t!=0)continue;
            if(u%(t*t)==0){
                cnt=-1;
                break;
            }
            cnt++;
        }
        if(cnt==-1)continue;
        ll r=nck(n/now,k/now);
        if(cnt%2==1)ans+=r;
        else ans-=r;
        ans=(ans+mod)%mod;
    }
    cout<<ans<<endl;
}
0