ENG  RUSTimus Online Judge
Online Judge
Задачи
Авторы
Соревнования
О системе
Часто задаваемые вопросы
Новости сайта
Форум
Ссылки
Архив задач
Отправить на проверку
Состояние проверки
Руководство
Регистрация
Исправить данные
Рейтинг авторов
Текущее соревнование
Расписание
Прошедшие соревнования
Правила
вернуться в форум

Обсуждение задачи 1068. Сумма

I can't get Accepted and I can't my mistake . Can You HELP MEEE!!!
Послано Ivo 25 май 2001 04:09
Here's the source can you find the mistake?

var i,sum1,n:longint;
begin
   readln(n);
   sum1:=0;
   if n=1 then sum1:=2
   else
     if n<=0 then
      for i:=1 downto n do sum1:=sum1+i;
     else
      for i:=1 to n do sum1:=sum1+i;
   writeln(sum1);
end.
Re: I can't get Accepted and I can't my mistake . Can You HELP MEEE!!!
Послано platypus 25 май 2001 12:29
> you had to check it!!! it has stupid error:
> before "else" - no ";"!!!!!
if u can't get AC, that means you have a mistake!!! and yours is ...
Послано Dinh Quang Hiep (mg9h@yahoo.com) 25 май 2001 17:01
when n = 1, the sum is 1 (not 2 like in your output)

btw, you have a formula for this problems, that is, the sum
of all interger numbers lying between N1 and N2 (N1 <= N2)
is

(N1 + N2) * (N2 - N1 + 1) / 2

Good luck !

DQH (DSAP Group)
Mg9h@yahoo.com
http://dsapvn.hypermart.net


> Here's the source can you find the mistake?
>
> var i,sum1,n:longint;
> begin
>    readln(n);
>    sum1:=0;
>    if n=1 then sum1:=2
>    else
>      if n<=0 then
>       for i:=1 downto n do sum1:=sum1+i;
>      else
>       for i:=1 to n do sum1:=sum1+i;
>    writeln(sum1);
> end.
>
>
if u can't get AC, that means you have a mistake!!! and yours is ...
Послано Dinh Quang Hiep (mg9h@yahoo.com) 25 май 2001 17:01
when n = 1, the sum is 1 (not 2 like in your output)

btw, you have a formula for this problems, that is, the sum
of all interger numbers lying between N1 and N2 (N1 <= N2)
is

(N1 + N2) * (N2 - N1 + 1) / 2

Good luck !

DQH (DSAP Group)
Mg9h@yahoo.com
http://dsapvn.hypermart.net


> Here's the source can you find the mistake?
>
> var i,sum1,n:longint;
> begin
>    readln(n);
>    sum1:=0;
>    if n=1 then sum1:=2
>    else
>      if n<=0 then
>       for i:=1 downto n do sum1:=sum1+i;
>      else
>       for i:=1 to n do sum1:=sum1+i;
>    writeln(sum1);
> end.
>
>
Re: if u can't get AC, that means you have a mistake!!! and yours is ...
Послано Donny Riyadi 25 май 2001 21:03
Hei, I've tried this formula, look at my source :
var
 i : integer;
 h : longint;
begin
readln(i);
h := i + 1;
h := h * i;
writeln((h/2):0:0);
end.

but i still got wrong answer, what's wrong. and btw, is
that's the formula, i think the example is wrong.
thanx


> when n = 1, the sum is 1 (not 2 like in your output)
>
> btw, you have a formula for this problems, that is, the
sum
> of all interger numbers lying between N1 and N2 (N1 <=
N2)
> is
>
> (N1 + N2) * (N2 - N1 + 1) / 2
>
> Good luck !
>
> DQH (DSAP Group)
> Mg9h@yahoo.com
> http://dsapvn.hypermart.net
>
>
> > Here's the source can you find the mistake?
> >
> > var i,sum1,n:longint;
> > begin
> >    readln(n);
> >    sum1:=0;
> >    if n=1 then sum1:=2
> >    else
> >      if n<=0 then
> >       for i:=1 downto n do sum1:=sum1+i;
> >      else
> >       for i:=1 to n do sum1:=sum1+i;
> >    writeln(sum1);
> > end.
> >
> >
Re: if u can't get AC, that means you have a mistake!!! and yours is ...
Послано Dinh Quang Hiep (mg9h@yahoo.com) 25 май 2001 22:50
No, the wrong things belong to you, the example is
absolutely right!
1. 'bout the example, n = -3, that the sequence is
    -3 -2 -1 0 1
    and the sum counted by
    (-3) + (-2) + (-1) + 0 + 1 = -5
    Is it right ?
2. Your prog is wrong, with my formula, you have to count
   the sum from input (in your prog is the variable i) to 1,
   that means the source must be something like this

   input i
   if i < 1 then sum = (( 1 + i) * ( 2 - i)) div 2;
   if i >=1 then sum = (( i + 1) * i) div 2;
   output sum
3. Don't use /2 if not nesscessary, just use div 2 for the
   correction.

Good luck !
QH@
> Hei, I've tried this formula, look at my source :
> var
>  i : integer;
>  h : longint;
> begin
> readln(i);
> h := i + 1;
> h := h * i;
> writeln((h/2):0:0);
> end.
>
> but i still got wrong answer, what's wrong. and btw, is
> that's the formula, i think the example is wrong.
> thanx
>
>
> > when n = 1, the sum is 1 (not 2 like in your output)
> >
> > btw, you have a formula for this problems, that is, the
> sum
> > of all interger numbers lying between N1 and N2 (N1 <=
> N2)
> > is
> >
> > (N1 + N2) * (N2 - N1 + 1) / 2
> >
> > Good luck !
> >
> > DQH (DSAP Group)
> > Mg9h@yahoo.com
> > http://dsapvn.hypermart.net
> >
> >
> > > Here's the source can you find the mistake?
> > >
> > > var i,sum1,n:longint;
> > > begin
> > >    readln(n);
> > >    sum1:=0;
> > >    if n=1 then sum1:=2
> > >    else
> > >      if n<=0 then
> > >       for i:=1 downto n do sum1:=sum1+i;
> > >      else
> > >       for i:=1 to n do sum1:=sum1+i;
> > >    writeln(sum1);
> > > end.
> > >
> > >
Re: if u can't get AC, that means you have a mistake!!! and yours is ...
Послано Lin Bo 1 дек 2001 22:08

> > Here's the source can you find the mistake?
> >
> > var i,sum1,n:longint;
> > begin
> >    readln(n);
> >    sum1:=0;
> >    if n=1 then sum1:=2
> >    else
> >      if n<=0 then------------------>this is the
mistakes ( n<=1 )
> >       for i:=1 downto n do sum1:=sum1+i;
> >      else
> >       for i:=1 to n do sum1:=sum1+i;
> >    writeln(sum1);
> > end.
> >
> >
very easy one , why u write it in this way ???
Послано Accepted 8 дек 2002 08:24
i don know why u use so such prog that run in O(n) my prog run
in O(1);
my mail is ioi_khafan@hotmail.com
here it is :
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.
Re: I can't get Accepted and I can't my mistake . Can You HELP MEEE!!!
Послано Sotl_Kamran 7 янв 2006 21:37
var
   n,k:integer;
   sum:longint;
begin
readln(n);
if n<0 then
begin for k:=n to 1 do
 sum:=sum+k; end
   else  if n>0 then begin for k:=1 to n do
     sum:=sum+k;
end;
write(sum);
end.
salam
men demek isteyirem ki bur daki sehv why