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 1068. Sum

something else wrong too...
Posted by A. B. Crest 14 Apr 2002 14:09
program sum(input,output);
var n,result : longint;
begin
     readln(n);
     if n >= 0 then result := n * (n+1) div 2
     else result := 1 + n * (1-n) div 2;
     writeln(result);
end.

when i tried this, i got WA(in case u are wondering, 0(0+1)/2 = 0),
however when i changed to the following i got AC...

program sum(input,output);
var n,result : longint;
begin
     readln(n);
     result := 0;
     if n > 0 then result := n * (n+1) div 2
     else result := 1 + n * (1-n) div 2;
     writeln(result);
end.

not that i'm insulting the compiler but the only conclusion i can
come to is the compiler thinks that 0(0+1)/2 <> 0...
btw, 1 + 0(1-0) div 2 = 0 too
Posted by A. B. Crest 14 Apr 2002 14:15