結果
| 問題 |
No.890 移調の限られた旋法
|
| コンテスト | |
| ユーザー |
DAyamaCTF
|
| 提出日時 | 2019-09-20 21:47:04 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 414 ms / 2,000 ms |
| コード長 | 1,481 bytes |
| コンパイル時間 | 1,418 ms |
| コンパイル使用メモリ | 158,824 KB |
| 実行使用メモリ | 26,880 KB |
| 最終ジャッジ日時 | 2024-09-14 17:09:35 |
| 合計ジャッジ時間 | 11,749 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 32 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll
#define INF 1e16
#define mod 1000000007
ll gcd(ll a,ll b){
return b?gcd(b,a%b):a;
}
ll mod_pow(ll a,ll n){
ll res=1;
while(n>0){
if(n&1)res=res*a%mod;
a=a*a%mod;
n>>=1;
}
return res;
}
bool vis[1000010];
ll res[1000010];
ll fac[1000010],finv[1000010];
ll comb(ll n,ll r){
if(n<0||r<0||n<r)return 0;
else return ((fac[n]*finv[r])%mod)*finv[n-r]%mod;
}
ll N,K;
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
fac[0]=1;
rep(i,1000000)fac[i+1]=fac[i]*(i+1)%mod;
rep(i,1000001)finv[i]=mod_pow(fac[i],mod-2);
cin>>N>>K;
repl(i,1,N){
ll g=gcd(N,i);
if(vis[g])continue;
vis[g]=true;
ll A=N/g;
ll B=N/A;
if(K%A==0){
ll cnt=K/A;
res[g]+=comb(B,cnt);
res[g]%=mod;
}
}
ll sum=0;
for(ll i=1;i<=N;i++){
if(vis[i])(sum+=res[i])%=mod;
for(ll j=2*i;j<=N;j+=i)(res[j]+=mod-res[i])%=mod;
}
cout<<sum<<endl;
return 0;
}
DAyamaCTF