|
|
вернуться в форумprogram ex; var now,i,l,k:longint; begin readln(k); now:=k; for i:=3 to trunc(sqrt(100000000)) do if k mod i=0 then begin now:=i; break; end; writeln(now-1); end. > program ex; > var > now,i,l,k:longint; > begin > readln(k); > now:=k; > for i:=3 to trunc(sqrt(100000000)) do > if k mod i=0 then begin now:=i; break; end; > writeln(now-1); > end. > what will you do when K is a prime number? For example,k=3. program ex; var now,i,l,k:longint; begin readln(k); now:=k; for i:=3 to 10000 do {trunc(sqrt(100000000))=10000} if k mod i=0 then begin now:=i; break; end; writeln(now-1); end. I have tried. Itself so thought. Wrong answer. I did so at the first time but got WA Try this test 1999966 the correct answer is 999982 but the result of your program is 1999965 ... In this problem, trunc(sqrt(100000000)) isn't a right limit. We should use (k div 2)+1 for the high limit,isn't it? is not. trunc(sqrt(k)) - rigth limit var n,l,i:longint; begin readln(n); l:=n-1; if ((n mod 2)=0) and (n div 2>2) then l:=n div 2-1; for i:=2 to trunc(sqrt(n)) do if n mod (i+1)=0 then begin l:=i; break end; writeln(l) end. |
|
|