結果
| 問題 |
No.890 移調の限られた旋法
|
| コンテスト | |
| ユーザー |
ゆきのん
|
| 提出日時 | 2019-09-20 23:14:11 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 43 ms / 2,000 ms |
| コード長 | 2,011 bytes |
| コンパイル時間 | 2,084 ms |
| コンパイル使用メモリ | 177,112 KB |
| 実行使用メモリ | 35,548 KB |
| 最終ジャッジ日時 | 2024-09-14 20:01:08 |
| 合計ジャッジ時間 | 4,894 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 32 |
ソースコード
#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;
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;
}
ゆきのん