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

Why dosn't work my program on the easiest problem?
Posted by Michael Medvedev (KNU training center) 15 Oct 2001 15:27
I wrote a program for 1068 "Sum" - the code is really very
easy. Judge program says always me "wrong answer". Where is
my mistake? Could anybody help me?

program p;
var i,n:integer;
    res:longint;
begin
  read(n);
  res := 0;
  if (n >=1) then
     for i:=1 to n do res := res + i
  else
     for i:=1 downto n do res := res + i;
  write(res);
end.
What was the problem?
Posted by Jicote Aguamielero 5 Sep 2002 11:49
What was the problem with your program?
Please tell me, 'cause as you can see, Ricardo have the same problem.
Re: Why dosn't work my program on the easiest problem?
Posted by zhangwuji 18 Feb 2006 15:06
I could only tell you about the right programme.
because my English is very bad.
Bellow is the answer.
var
 n:longint;
begin
  readln(n);
  writeln((1+n)*(abs(n-1)+1)div 2);
end.