Pagini recente » Cod sursa (job #945736) | Cod sursa (job #2539124) | Cod sursa (job #1177588) | Cod sursa (job #2376950) | Cod sursa (job #34621)
Cod sursa(job #34621)
type vector=array[1..100] of 0..1;
var f,g:text;
a,b,c,m,n,p,lv,i,j:longint;
x:vector;
v:array[1..100] of longint;
function prime(c:longint):boolean;
begin
if c mod 5=0 then prime:=true
else prime:=false;
end;
procedure adauga(var x:vector);
begin
if x[lv]=0 then x[lv]:=1
else
begin
x[lv]:=0;
j:=lv-1;
while x[j]=1 do
begin
x[j]:=0;
dec(j);
end;
x[j]:=1;
end;
end;
function ver(c:longint):longint;
var w,q,pp:longint;
ok:boolean;
begin
w:=0;
for j:=1 to lv do
begin
w:=w+c div v[j];
end;
{fillchar(x,lv,0);
ok:=true;
while ok do
begin
adauga(x);
q:=0;
pp:=1;
for j:=1 to lv do if x[j]=1 then begin inc(q); pp:=pp*v[j] div j; end;
if q mod 2=0 then w:=w+c div pp
else w:=w-(c div pp);
if q=lv then ok:=false;
end; }
ver:=w;
end;
function cauta(a,b:longint): longint;
var t:longint;
begin
if a=b then t:=a
else
begin
c:=(a+b) div 2;
m:=ver(c);
if (m=p) and (prime(c))
then t:=c else
if m>=p then t:=cauta(a,c)
else t:=cauta(c+1,b); end;
cauta:=t;
end;
begin
assign(f,'fact.in');
reset(f);readln(f,p);
close(f);
lv:=7;
v[1]:=5;
for i:=2 to 7 do v[i]:=v[i-1]*5;
assign(g,'fact.out');
rewrite(g);
if p=0 then writeln(g,'1') else writeln(g,cauta(0,100));
close(g);
end.