A combination of computing integer factorial

Description of the problem: Given a positive integer n, a, seeking the maximum k, so that n! It may be a ^ k divisible but not by a ^ (k + 1) is divisible.

n and uses a primary input () call inputs, two numbers a comma (,) separated directly outputs the value of k.

For example: Enter 100,9

   Output 24

import math

i=input()
ii=i.split(',')
n=eval(ii[0])
a=eval(ii[1])
jc=math.factorial(n)
l=int(math.log(jc,a))
while l>=0:
if(jc%a**l==0 and jc%a**(l+1)!=0):
print(l)
break
l=l-1

Guess you like

Origin www.cnblogs.com/huanghuangwei/p/11597103.html