Pagini recente » Cod sursa (job #1714035) | Cod sursa (job #1048283) | Cod sursa (job #94243) | Cod sursa (job #2874575) | Cod sursa (job #373780)
Cod sursa(job #373780)
program Project1;
{$APPTYPE CONSOLE}
function GetFactZero(X: Longint): Longint;
var div5, c: integer;
begin
div5 := 0;
c := -1;
while X > 4 do
begin
div5 := div5 + (X div 5);
x := x div 5;
inc(c);
end;
if X = 0 then
div5 := div5 + c;
GetFactZero := (X div 25) + div5;
end;
const cale = 'D:\fact\fact.';
var x, y, xy, lr, P: longint; // last result
fil: Text;
begin
x := 1;
y := 2147483647;
Assign(fil, cale + 'in');
Reset(fil);
Read(fil, P);
Close(fil);
// P := 2; // read from file
repeat
xy := (x shr 1) + (y shr 1);
lr := GetFactZero(xy);
if (lr = P) or ((x = xy) or (xy = y))
then Break
else
if lr < P
then
begin
x := xy;
end
else
begin
y := xy;
end
until False;
if (lr = P)
then
begin
xy := xy - (xy mod 5);
Assign(fil, cale + 'out');
Rewrite(fil);
Write(fil, xy);
Close(fil);
// write('Result = ', xy)
end
else
begin
Assign(fil, cale + 'out');
Rewrite(fil);
Write(fil, '-1');
Close(fil);
// write('That''s all, folks !');
end;
end.