結果
問題 | No.890 移調の限られた旋法 |
ユーザー |
![]() |
提出日時 | 2019-09-21 09:11:53 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 104 ms / 2,000 ms |
コード長 | 919 bytes |
コンパイル時間 | 1,641 ms |
コンパイル使用メモリ | 170,660 KB |
実行使用メモリ | 34,484 KB |
最終ジャッジ日時 | 2024-09-17 06:38:07 |
合計ジャッジ時間 | 5,086 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 32 |
ソースコード
#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; }