Re: if u can't get AC, that means you have a mistake!!! and yours is ...
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.
> > >
> > >