|
|
вернуться в форумWhy can not AC? Послано zj_zcy 15 июн 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? Послано freeze 8 июл 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? zj_zcy, what if n = 3 ? Your program wrote 0, but right answer 2 Re: Why can not AC? 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? Your code will possibly fail for integers like 2*n,also for test cases where n is a prime number |
|
|