結果

問題 No.890 移調の限られた旋法
ユーザー leaf_1415leaf_1415
提出日時 2019-09-20 22:23:59
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 35 ms / 2,000 ms
コード長 1,356 bytes
コンパイル時間 806 ms
コンパイル使用メモリ 66,540 KB
実行使用メモリ 24,996 KB
最終ジャッジ日時 2023-10-12 19:50:35
合計ジャッジ時間 2,704 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
20,636 KB
testcase_01 AC 17 ms
20,620 KB
testcase_02 AC 17 ms
20,644 KB
testcase_03 AC 17 ms
20,732 KB
testcase_04 AC 17 ms
20,620 KB
testcase_05 AC 17 ms
20,836 KB
testcase_06 AC 18 ms
20,612 KB
testcase_07 AC 17 ms
20,740 KB
testcase_08 AC 18 ms
20,612 KB
testcase_09 AC 17 ms
20,616 KB
testcase_10 AC 17 ms
20,736 KB
testcase_11 AC 17 ms
20,656 KB
testcase_12 AC 17 ms
20,612 KB
testcase_13 AC 35 ms
22,760 KB
testcase_14 AC 34 ms
20,740 KB
testcase_15 AC 34 ms
22,720 KB
testcase_16 AC 35 ms
22,832 KB
testcase_17 AC 33 ms
23,008 KB
testcase_18 AC 33 ms
22,872 KB
testcase_19 AC 27 ms
24,868 KB
testcase_20 AC 24 ms
22,664 KB
testcase_21 AC 19 ms
20,660 KB
testcase_22 AC 31 ms
24,716 KB
testcase_23 AC 33 ms
20,656 KB
testcase_24 AC 27 ms
24,996 KB
testcase_25 AC 19 ms
20,652 KB
testcase_26 AC 33 ms
22,876 KB
testcase_27 AC 34 ms
20,876 KB
testcase_28 AC 29 ms
22,708 KB
testcase_29 AC 24 ms
22,684 KB
testcase_30 AC 33 ms
22,820 KB
testcase_31 AC 26 ms
22,760 KB
testcase_32 AC 32 ms
23,068 KB
testcase_33 AC 33 ms
22,840 KB
testcase_34 AC 32 ms
23,052 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <map>
#include <vector>
#define llint long long
#define mod 1000000007

using namespace std;

const int FACT_MAX = 1000005;
llint fact[FACT_MAX], fact_inv[FACT_MAX];

llint modpow(llint a, llint n)
{
	if(n == 0) return 1;
	if(n % 2){
		return ((a%mod) * (modpow(a, n-1)%mod)) % mod;
	}
	else{
		return modpow((a*a)%mod, n/2) % mod;
	}
}

void make_fact()
{
	llint val = 1;
	fact[0] = 1;
	for(int i = 1; i < FACT_MAX; i++){
		val *= i;
		val %= mod;
		fact[i] = val;
	}
	fact_inv[FACT_MAX-1] = modpow(fact[FACT_MAX-1], mod-2);
	for(int i = FACT_MAX-2; i >= 0; i--){
		fact_inv[i] = fact_inv[i+1] * (i+1) % mod;
	}
}

llint comb(llint n, llint k)
{
	llint ret = 1;
	ret *= fact[n];
	ret *= fact_inv[k], ret %= mod;
	ret *= fact_inv[n-k], ret %= mod;
	return ret;
}

llint n, k;
vector<int> vec;
llint dp[1000005];

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> k;
	make_fact();
	
	for(int i = 1; i <= n; i++){
		if(n % i == 0) vec.push_back(i);
	}
	
	for(int x = 0; x < vec.size(); x++){
		int i = vec[x];
		if(k % (n/i)) continue;
		dp[i] = comb(i, k/(n/i));
		for(int j = 0; j < vec.size(); j++){
			if(vec[j] == i) break;
			if(i % vec[j] == 0) dp[i] += mod - dp[vec[j]], dp[i] %= mod;
		}
	}
	
	llint ans = 0;
	for(int i = 1; i < n; i++) ans += dp[i], ans %= mod;
	cout << ans << endl;
	
	return 0;
}
0