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 1023. Buttons

var
  i,n,l,j:longword; found:boolean;
begin
  readln(n);
  repeat
  found:=False;
  for j:=3 to n div 2 do
  begin
    if n mod j=0 then
    begin
      found:=True;
      break;
    end;
  end;
  if found then n:=j;
  until not found;
  writeln(n-1);
  readln;
end.

Please help me to optimize my code. It's 0.405 sec

 for j := 3 to sqrt(n) do  will help you :)
> for j := 3 to sqrt(n) do  will help you :)

will it? for sqrt(8) = 2.8, but answer should be 4 - 1 = 3