My Solution:You should only find the minimum number l that can be divide by k,if no such number l,write(k-1) else write(l-1)
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.
No shit!
> 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.
>
Re: No shit!
what will you do when K is a prime number?
For example,k=3.
Re: My Solution:You should only find the minimum number l that can be divide by k,if no such number l,write(k-1) else write(l-1)
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.
Re: My Solution:You should only find the minimum number l that can be divide by k,if no such number l,write(k-1) else write(l-1)
Послано
Neo 4 июн 2004 22:33
I have tried.
Itself so thought.
Wrong answer.
Re: My Solution:You should only find the minimum number l that can be divide by k,if no such number l,write(k-1) else write(l-1)
Послано
ss 5 июл 2004 13:59
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
...
The answer is incorrect!
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?
I don't think it can get AC! Here's mine
Послано
yuwei 27 окт 2004 18:11
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.
Re: The answer is incorrect!
is not. trunc(sqrt(k)) - rigth limit