結果

問題 No.890 移調の限られた旋法
ユーザー leaf_1415leaf_1415
提出日時 2019-09-20 22:06:15
言語 C++11
(gcc 11.4.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,439 bytes
コンパイル時間 503 ms
コンパイル使用メモリ 66,596 KB
実行使用メモリ 205,560 KB
最終ジャッジ日時 2023-10-12 19:24:03
合計ジャッジ時間 73,855 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,947 ms
201,336 KB
testcase_01 AC 1,969 ms
201,348 KB
testcase_02 AC 1,909 ms
201,348 KB
testcase_03 AC 1,956 ms
201,412 KB
testcase_04 AC 1,919 ms
201,568 KB
testcase_05 AC 1,920 ms
201,568 KB
testcase_06 AC 1,921 ms
201,344 KB
testcase_07 AC 1,936 ms
201,436 KB
testcase_08 AC 1,936 ms
201,616 KB
testcase_09 AC 1,973 ms
201,280 KB
testcase_10 AC 1,954 ms
201,612 KB
testcase_11 TLE -
testcase_12 AC 1,988 ms
201,616 KB
testcase_13 AC 1,979 ms
203,484 KB
testcase_14 AC 1,952 ms
201,296 KB
testcase_15 AC 1,965 ms
203,668 KB
testcase_16 AC 1,969 ms
203,500 KB
testcase_17 TLE -
testcase_18 AC 1,981 ms
203,572 KB
testcase_19 AC 1,960 ms
205,560 KB
testcase_20 AC 1,958 ms
203,332 KB
testcase_21 AC 1,962 ms
201,280 KB
testcase_22 TLE -
testcase_23 AC 1,952 ms
201,364 KB
testcase_24 AC 1,941 ms
205,388 KB
testcase_25 AC 1,906 ms
201,348 KB
testcase_26 AC 1,963 ms
203,348 KB
testcase_27 AC 1,944 ms
201,348 KB
testcase_28 AC 1,988 ms
203,344 KB
testcase_29 AC 1,983 ms
203,396 KB
testcase_30 AC 1,999 ms
203,812 KB
testcase_31 AC 1,942 ms
203,556 KB
testcase_32 AC 1,946 ms
203,888 KB
testcase_33 AC 1,961 ms
203,772 KB
testcase_34 AC 1,961 ms
203,492 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 gcd(llint a, llint b){
	if(b == 0) return a;
	return gcd(b, a%b);
}

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

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> k;
	make_fact();
	
	for(int i = 1; i <= 1000000; i++){
		for(int j = 2; i*j <= 1000000; j++){
			vec[i*j].push_back(i);
		}
	}
	
	for(int i = 1; i <= n; i++){
		if(n % i) continue;
		if(k % (n/i)) continue;
		dp[i] = comb(i, k/(n/i));
		for(int j = 0; j < vec[i].size(); j++){
			dp[i] += mod - dp[vec[i][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