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

I have AC with such idea but I don't understand how to get a formula or faster solution
Posted by IlushaMax 17 Apr 2016 15:24
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
Re: I have AC with such idea but I don't understand how to get a formula or faster solution
Posted by c_pp 17 Dec 2016 23:35

 for j := 3 to sqrt(n) do  will help you :)
Re: I have AC with such idea but I don't understand how to get a formula or faster solution
Posted by PO 18 Jan 2019 12:11
> for j := 3 to sqrt(n) do  will help you :)

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