結果

問題 No.890 移調の限られた旋法
コンテスト
ユーザー tekihei2317
提出日時 2019-09-21 09:11:53
言語 C++14
(gcc 15.3.0 + boost 1.92.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 42 ms / 2,000 ms
+ 240µs
コード長 919 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 933 ms
コンパイル使用メモリ 182,304 KB
実行使用メモリ 34,560 KB
最終ジャッジ日時 2026-08-29 08:47:45
合計ジャッジ時間 3,918 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<bits/stdc++.h>
#define int long long
using namespace std;

const int mod=1e9+7;
const int sz=1000010;

int fact[sz],inv[sz],ifact[sz];
void make(){
    fact[0]=fact[1]=inv[1]=ifact[0]=ifact[1]=1;
    for(int i=2;i<sz;i++){
        fact[i]=fact[i-1]*i%mod;
        inv[i]=inv[mod%i]*(mod-mod/i)%mod;
        ifact[i]=ifact[i-1]*inv[i]%mod;
    }
}
int comb(int n,int k){
    if(n<k) return 0;
    return fact[n]*ifact[k]%mod*ifact[n-k]%mod;
}

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    make();
    int N,K; cin>>N>>K;

    vector<int> dp(N);
    for(int i=1;i<N;i++) if(N%i==0){
        int j=N/i;
        if(K%j==0){
            dp[i]=comb(i,K/j);
        }
    }
    int ans=0;
    for(int i=1;i<N;i++) if(N%i==0){
        ans=(ans+dp[i])%mod;
        for(int j=i*2;j<N;j+=i) if(N%j==0){
            dp[j]=(dp[j]-dp[i]+mod)%mod;
        }
    }
    cout<<ans<<endl;
    return 0;
}
0