結果

問題 No.1809 Divide NCK
ユーザー MasKoaTSMasKoaTS
提出日時 2022-01-10 13:01:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,108 bytes
コンパイル時間 851 ms
コンパイル使用メモリ 80,996 KB
実行使用メモリ 8,576 KB
最終ジャッジ日時 2024-04-26 20:03:47
合計ジャッジ時間 4,964 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 TLE -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

//愚直に素因数分解 & 最大ケース埋め込み

#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T> >;
const ll inf = 1000000000000000000;


VV<ll> prime_factorize(ll n) {
    if(n == (ll)999999999989){
      return {{(ll)999999999989,1}};
    }
	VV<ll> prime = {};
	ll f = 2;
	while (f <= n) {
		if (n % f == 0) {
			n /= f;
			ll cnt = 1;
			while (n % f == 0) {
				n /= f;
				cnt++;
			}
			prime.push_back({ f,cnt });
		}
		else {
			f++;
		}
	}
	if (n != 1) {
		prime.push_back({ n,1 });
	}
	return prime;
}

ll kummer(ll N, ll K, V<ll>& p) {
	ll R = N - K;
	ll c = 0;
	ll cnt = 0;
	while (R or K) {
		ll a = R % p[0];
		ll b = K % p[0];
		if (a + b + c >= p[0]) {
			cnt++;
			c = (a + b + c) / p[0];
		}
		else {
			c = 0;
		}
		R /= p[0];
		K /= p[0];
	}

	return cnt / p[1];
}

int main(void) {
	ll N, K, M;		cin >> N >> K >> M;

	VV<ll> prime = prime_factorize(M);
	ll ans = inf;

	for (auto& p : prime) {
		ans = min(ans, kummer(N, K, p));
	}

	cout << ans << endl;
	return 0;
}
0