ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1118. Nontrivial Numbers

Why I get WA? Help me PLS!!!
Posted by M.Si 24 May 2002 12:58
{$N+}
var
  t1,t2:extended;
  num,i,j,k,divisor:longint;
  s:string;
function triv(n:longint):extended;
var i,j, counter:longint;
begin
  j:=round(sqrt(n)); counter:=0;
  divisor:=0;
  for i:=1 to j do
    if n mod i=0 then begin
      inc(counter,i);
      inc(divisor);
    end;
  if counter>1 then
    for i:=j+1 to n div 2 do
      if n mod i =0 then
      begin
        inc(counter,i);
        inc(divisor);
      end;
  triv:=counter/n;
end;
procedure die(s:string);
begin
  writeln(s); halt(0);
end;

begin
  writeln('Input I and J');
  read(i,j);
  if i<=0 then die('wrong input');
  if j>=1000000 then die('wrong input');
  if i=j then begin
    str(i,s);
    die(s);
  end;
  if i=1 then begin
    str(1,s);
    die(s);
  end;
  t1:=maxlongint;
  for k:=j downto i do
  begin
    t2:=triv(k);
    if t2<t1 then begin
      t1:=t2;
      num:=k;
      if divisor=1 then begin str(k,s); die(s) end;
    end;
  end;
  writeln(num);
end.