結果

問題 No.890 移調の限られた旋法
ユーザー pockynypockyny
提出日時 2019-09-20 22:45:23
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 89 ms / 2,000 ms
コード長 905 bytes
コンパイル時間 799 ms
コンパイル使用メモリ 77,192 KB
実行使用メモリ 30,836 KB
最終ジャッジ日時 2023-10-12 20:28:52
合計ジャッジ時間 4,284 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 57 ms
28,448 KB
testcase_01 AC 58 ms
28,416 KB
testcase_02 AC 57 ms
28,516 KB
testcase_03 AC 57 ms
28,580 KB
testcase_04 AC 57 ms
28,436 KB
testcase_05 AC 56 ms
28,524 KB
testcase_06 AC 58 ms
28,432 KB
testcase_07 AC 57 ms
28,476 KB
testcase_08 AC 56 ms
28,460 KB
testcase_09 AC 57 ms
28,496 KB
testcase_10 AC 57 ms
28,588 KB
testcase_11 AC 57 ms
28,400 KB
testcase_12 AC 57 ms
28,504 KB
testcase_13 AC 76 ms
30,668 KB
testcase_14 AC 60 ms
28,580 KB
testcase_15 AC 74 ms
30,528 KB
testcase_16 AC 76 ms
30,596 KB
testcase_17 AC 75 ms
30,536 KB
testcase_18 AC 82 ms
30,628 KB
testcase_19 AC 64 ms
30,656 KB
testcase_20 AC 58 ms
28,536 KB
testcase_21 AC 57 ms
28,508 KB
testcase_22 AC 66 ms
30,764 KB
testcase_23 AC 60 ms
28,712 KB
testcase_24 AC 62 ms
30,560 KB
testcase_25 AC 59 ms
28,464 KB
testcase_26 AC 72 ms
30,484 KB
testcase_27 AC 63 ms
28,452 KB
testcase_28 AC 60 ms
28,644 KB
testcase_29 AC 60 ms
28,428 KB
testcase_30 AC 81 ms
30,700 KB
testcase_31 AC 66 ms
28,672 KB
testcase_32 AC 89 ms
30,672 KB
testcase_33 AC 81 ms
30,836 KB
testcase_34 AC 71 ms
30,632 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
const int MAX = 1000010;
ll inv[MAX],fact[MAX],fi[MAX],mod = 1000000007;
void inverse(){
	int i;
	inv[1] = 1;
	for(i=2;i<MAX;i++){
		inv[i] = mod - (mod/i)*inv[mod%i]%mod;
	}
	fact[0] = fi[0] = 1;
	for(i=1;i<MAX;i++){
		fact[i] = fact[i-1]*i%mod;
		fi[i] = (fi[i-1]*inv[i])%mod;
	}
}

ll comb(int n,int k){
	if(n<0 || k<0 || n<k){
		return 0;
	}else{
		return fact[n]%mod*fi[k]%mod*fi[n-k]%mod;
	}
}
ll ans = 0,cnt[1000010] = {};
vector<ll> v;
int main(){
	int i,j,n,k;
	cin >> n >> k;
	for(i=1;i<n;i++){
		if(n%i==0){
			v.push_back(i);
		}
	}
	inverse();
	for(i=0;i<v.size();i++){
		ll x = v[i];
		if(k%(n/x)!=0) continue;
		cnt[x] = comb(x,k/(n/x));
		for(j=1;j<x;j++){
			if(x%j==0){
				cnt[x] -= cnt[j];
				if(cnt[x]<0) cnt[x] += mod;
			}
		}
		(ans += cnt[x]) %= mod;
	}
	cout << ans << endl;
}
0