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:31
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:longint;
    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.
Something's wrong with downto there!
Posted by shitty.Mishka 15 Oct 2001 18:06
I just took your solution and changed loop downto a little.
This will be accepted: (has already been:).
Mind that you don't have to use loop at all - just using
formula n*(n+1)/2 seperately for n>=1 and n<1 :)
I can post my solution here if you want, or send it by email

program p;
var i,n:longint;
    res:longint;
begin
  read(n);
  res := 0;
  if (n >=1) then
     for i:=1 to n do res := res + i
  else begin
     res:=1;
     for i:=1 to -n do res := res - i;
  end;
  write(res);
end.