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

var sol,gam,i,j,k,m,n:longint;
    min,min1:real;

procedure readdata;
  begin
    readln (n,m);
  end;

procedure solve;
  begin
    min:=n;
    if n=1 then
     begin
       writeln (1);
       halt;
     end;
    min1:=m;
    for i:=n to m do
      begin
        k:=i div 2;
        for j:=2 to k do
          if i mod j = 0 then
            gam:=gam+j;
        min:=gam/i;
        if min1>min then
          begin
            sol:=i;
            min1:=min;
          end;
        gam:=1;
      end;
  end;

procedure print;
  begin
    writeln (sol);
  end;

begin
  readdata;
  solve;
  print;
end.

try this test   1 1000000    => time limit of course
  O( n * (n + 1) / 4 ) => too big.
Thinhk more little , you will find something interesting.
Good luck