結果

問題 No.890 移調の限られた旋法
ユーザー tkmst201tkmst201
提出日時 2019-09-20 22:48:00
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,959 bytes
コンパイル時間 1,355 ms
コンパイル使用メモリ 155,012 KB
実行使用メモリ 36,544 KB
最終ジャッジ日時 2023-10-12 20:33:24
合計ジャッジ時間 5,640 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
35,992 KB
testcase_01 AC 83 ms
35,932 KB
testcase_02 AC 83 ms
36,112 KB
testcase_03 AC 83 ms
35,944 KB
testcase_04 AC 82 ms
36,180 KB
testcase_05 AC 83 ms
36,244 KB
testcase_06 AC 84 ms
36,044 KB
testcase_07 AC 82 ms
35,948 KB
testcase_08 AC 83 ms
36,244 KB
testcase_09 AC 83 ms
35,948 KB
testcase_10 AC 83 ms
36,044 KB
testcase_11 AC 84 ms
36,112 KB
testcase_12 AC 82 ms
36,172 KB
testcase_13 AC 83 ms
36,188 KB
testcase_14 AC 83 ms
36,108 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 83 ms
35,988 KB
testcase_21 AC 82 ms
35,936 KB
testcase_22 AC 82 ms
36,184 KB
testcase_23 AC 83 ms
35,936 KB
testcase_24 AC 83 ms
35,992 KB
testcase_25 AC 83 ms
35,932 KB
testcase_26 AC 83 ms
35,936 KB
testcase_27 AC 83 ms
36,060 KB
testcase_28 AC 82 ms
36,056 KB
testcase_29 AC 83 ms
36,184 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 82 ms
36,176 KB
testcase_34 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll INF = 1ll<<30;
const ll longINF = 1ll<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;
const bool debug = 0;
//---------------------------------//

vector<ll> findDivisor(ll n) {
	vector<ll> divisor;
	for (ll i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			divisor.push_back(i);
			if (i * i != n) divisor.push_back(n / i);
		}
	}
	sort(ALL(divisor));
	return divisor;
}

ll mod_pow(ll x, ll n, ll mod) {
	if (n == 0) return 1;
	ll res = mod_pow(x * x % mod, n / 2, mod);
	if (n & 1) res = res * x % mod;
	
	return res;
}

vector<ll> fact, inv;
void fact_inv(int n, ll mod) {
	fact.resize(n + 1);
	inv.resize(n + 1);
	
	fact[0] = 1;
	FOR(i, 1, n + 1) fact[i] = fact[i - 1] * i % mod;
	inv[n] = mod_pow(fact[n], mod - 2, mod);
	for (int i = n; i > 0; i--) inv[i - 1] = inv[i] * i % mod;
}

// nCr % modを求める(modは素数)
ll ncr(ll n, ll r, ll mod) {
	if (n < r || r < 0 || n < 0) return 0;
	return fact[n] * inv[r] % mod * inv[n - r] % mod;
}

int main() {
	fact_inv(2123456, MOD);
	ll N, K;
	cin >> N >> K;
	vector<ll> divisor = findDivisor(N);
	vector<pll> defelem;
	
	ll ans = 0;
	REP(i, divisor.size()) {
		if (divisor[i] == N) continue;
		int d = N / divisor[i];
		if (K % d != 0) continue;
		int cc = K / d;
		ll cur = ncr(divisor[i], cc, MOD);
		REP(j, defelem.size()) if (divisor[i] % defelem[j].fi == 0) {
			cur = (cur - defelem[j].se + MOD) % MOD;
		}
		defelem.push_back(pll(divisor[i], cur));
		ans += cur;
	}
	
	cout << ans << endl;
	return 0;
}
0