|
|
back to boardShow all messages Hide all messagesvar 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 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. zj_zcy, what if n = 3 ? Your program wrote 0, but right answer 2 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. Your code will possibly fail for integers like 2*n,also for test cases where n is a prime number |
|
|