Pagini recente » Cod sursa (job #2829068) | Cod sursa (job #2280650) | Cod sursa (job #2004615) | Cod sursa (job #1640697) | Cod sursa (job #614874)
Cod sursa(job #614874)
Program gfact;
type tip=record
fact,put:int64;
end;
var p:array [1..1000] of tip;
a,q,max,b:int64;
i,n:longint;
fi,fo:text;
procedure descompune();
var j,k,s:int64;
begin
i:=2; k:=0;
while i<=trunc(sqrt(a)) do
if a mod i<>0 then inc(i)
else begin
inc(k);
p[k].fact:=i; s:=0;
repeat
inc(s);
a:=a div i;
until (a=1) or (a mod i<>0);
p[k].put:=s*q;
inc(i);
end;
if a>1 then begin p[k+1].fact:=a; p[k+1].put:=q; n:=k+1; end
else n:=k;
end;
procedure cauta(l,r:int64);
var mid,k:int64;
j:int64;
begin
j:=p[i].fact; k:=0;
mid:=(l+r) div 2;
while trunc(mid/j)>0 do begin
k:=k+trunc(mid/j);
j:=j*j;
end;
if l<r then begin
if k>=p[i].put then cauta(l,mid-1)
else if k<p[i].put then cauta(mid+1,r);
end
else begin
if k>=p[i].put then b:=mid
else b:=mid+1;
end;
end;
procedure get_fact();
begin
for i:=1 to n do begin
cauta(1,p[i].put*p[i].fact);
if b>max then max:=b;
end;
end;
begin
assign(fi,'gfact.in');
assign(fo,'gfact.out');
reset(fi); rewrite(fo);
readln(fi,a,q);
if a=1 then write(fo,'1')
else begin descompune();
get_fact();
write(fo,max);
end;
close(fo);
end.