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

Why can not AC?
Posted by zj_zcy 15 Jun 2008 14:10
var n,i,j:longint;
begin
  readln(n);
  if (n<=2)then begin writeln('0') ; halt; end;
  j:=trunc(sqrt(n));
  for i:=3 to j do
    begin
      if (n mod i=0) then break;
    end;
  writeln(i-1);
end.


Can anybody tell me why?
It seems rigth^Why ? It drives me crazy^

Edited by author 15.06.2008 14:10

Edited by author 15.06.2008 14:10
Re: Why can not AC?
Posted by freeze 8 Jul 2008 19:04
I think your j should be n div 2,and I promise it's not TLE.And you can define 'ans' to store the answer and let it equal n.That's all.
Re: Why can not AC?
Posted by →MOPDOBOPOT← 25 Jun 2009 15:08
zj_zcy, what if n = 3 ?
Your program wrote 0, but right answer 2
Re: Why can not AC?
Posted by Partisan 25 Jun 2009 15:54
The trouble is if n is big prime.
Try this:
99999989
The answer is:
99999988.

Think how to modify algorithm to catch big primes in factorization. Here it isn't necessary, but it will be useful.
Re: Why can not AC?
Posted by Woodpecker 13 Jan 2012 14:06
Your code will possibly fail for integers like 2*n,also for test cases where n is a prime number