MAXNUM - MAXNUM
Tác giả: ladpro98
Ngôn ngữ: Pascal
program maxnum;
uses math;
var n,p,s:longint;
res:int64;
tsp,tsn:array[1..30001] of longint;
procedure tinhp(p:longint);
var i:longint;
begin
i:=2;
while i<=p do
begin
if p mod i = 0 then
begin
while p mod i = 0 do
begin
p:=p div i;
inc(tsp[i]);
end;
end;
inc(i);
end;
end;
procedure tinhn;
var i,mu:longint;
begin
for i:=2 to p do
begin
if tsp[i] = 0 then continue;
mu:=i;
while mu<=n do
begin
inc(tsn[i],n div mu);
mu:=mu*i;
end;
end;
end;
procedure process;
var i:longint;
begin
for i:=2 to p do
begin
if tsp[i] = 0 then continue;
res:=min(res,tsn[i] div tsp[i]);
end;
end;
begin
readln(n,p);
res:=high(longint);
tinhp(p);
tinhn;
process;
write(res);
end.