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

I know why does many people got WA!!!!!!!!!!!!
Posted by wangtao 1 Nov 2002 19:06
I know why does many people got WA!!!!!!!!!!!!
When the n is 0,the result must be 1!!!!!!!!!!!!!!
(I'm not from the English-speaking country,my English is very bad.)
If there's someting wrong,please tell me,thanks)
Thanks i know a better way :-)
Posted by Accepted 8 Dec 2002 08:28
instead of suming u can use this formula :
1+2+3+...+n := n*(n+1) /2;
here is my prog :
ioi_khafan@hotmail.com

var
   n    : longint;
begin
  read (n);
  if  n = 0 then
      begin
           writeln ('1');
           exit;
      end
  else
  if n > 0 then
     n := ( n * (n + 1) ) div 2
  else
      begin
           n := -1 * n;
           n := ( n * (n + 1) ) div 2;
           n := n - 1;
           n := -1 * n;
      end;
  writeln (n);
end.
Let use shorter Code ! dear voyager
Posted by Locomotive 15 Mar 2003 08:25
Var
  n                   :integer;
  sum                 :longint;
begin
  readln(n);
  if n=0 then n:=1;
  sum:=abs(n)*(abs(n)+1) div 2;
  if n<0 then sum:=1-sum;
  writeln(sum);
  readln;
end.
Re: I know why does many people got WA!!!!!!!!!!!!
Posted by realsy 6 Sep 2005 22:45
Thanks!
BTW,I am familiar with your english.
Beacuse I can read Chnglish at ZJU. -_-||
Re: I know why does many people got WA!!!!!!!!!!!!
Posted by Rasul 20 Oct 2005 23:52
thanks for the help
As you see my English too not so !