結果

問題 No.1809 Divide NCK
ユーザー MasKoaTS
提出日時 2021-12-08 22:44:55
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 202 ms / 2,000 ms
コード長 559 bytes
コンパイル時間 80 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-11-14 10:52:00
合計ジャッジ時間 3,035 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 39
権限があれば一括ダウンロードができます

ソースコード

diff #

N,K,M = map(int,input().split())

def prime_factorize(n):
	prime = []
	f = 2
	while(f * f <= n):
		if(n % f == 0):
			n //= f
			cnt = 1
			while(n % f == 0):
				n //= f
				cnt += 1
			prime.append((f,cnt))
		else:
			f += 1
	if(n != 1):
		prime.append((n,1))
	return prime

def legendre(N,K,p,c):
	R = N - K
	cnt = 0
	while(N):
		N //= p
		cnt += N
	while(K):
		K //= p
		cnt -= K
	while(R):
		R //= p
		cnt -= R
	return cnt // c

prime = prime_factorize(M)
ans = 10 ** 18
for p,c in prime:
	cnt = legendre(N,K,p,c)
	if(ans > cnt):
		ans = cnt

print(ans)
0