結果

問題 No.1809 Divide NCK
コンテスト
ユーザー MasKoaTS
提出日時 2022-01-13 21:50:42
言語 Python3
(3.14.3 + numpy 2.4.4 + scipy 1.17.1)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 215 ms / 2,000 ms
コード長 1,119 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 451 ms
コンパイル使用メモリ 20,828 KB
実行使用メモリ 15,836 KB
最終ジャッジ日時 2026-05-12 10:22:06
合計ジャッジ時間 7,676 ms
ジャッジサーバーID
(参考情報)
tmp-judge_0 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 39
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import itertools as iter
import collections as coll
import heapq as hq
import bisect as bis
from decimal import Decimal as dec
from copy import deepcopy as dcopy
import math
import sys
sys.setrecursionlimit(10**6)
def input():
    return sys.stdin.readline().rstrip()
def getN():
	return int(sys.stdin.readline())
def getNs():
	return map(int,sys.stdin.readline().split())
def getList():
	return list(map(int,sys.stdin.readline().split()))
def strinps(n):
	return [sys.stdin.readline().rstrip() for _ in range(n)]
pi = 3.141592653589793
mod = 10**9+7
MOD = 998244353
INF = math.inf
dx = [1,0,-1,0];	dy = [0,1,0,-1]

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

def legendre(n, k, p):
	res = 0
	r = n - k
	while(n):
		n //= p
		res += n
	while(k):
		k //= p
		res -= k
	while(r):
		r //= p
		res -= r
	return res

"""
Main Code
"""

N, K, M = getNs()
ans = 10 ** 18
for p, c in prime_factorize(M):
	ans = min(ans, legendre(N, K, p) // c)
print(ans)
0