|
|
вернуться в форумI got AC with an 28K program!! Послано Drizzt 15 мар 2003 08:08 program Sum (input, output); var lI, lN : longint; begin readln (lN); if lN > 0 then lI := (lN + 1) * lN div 2; if lN = 0 then lI := 1; if lN < 0 then lI := (abs (lN) + 1) * lN div 2 + 1; writeln (lI); end. it isn`t too intresting is it?!!!! i used less memory than you :D (+) 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. ~~~~~~~~~~~~~~ u used 2 Longint (2*4b) and mine 1longint (4) + a Integer (2) so 4+2<2*4 !!! :P Please Stop sending AC dear, Best Regards Aidin_n7 Wow! You are both the best programmers in the world! I couldn't ever dream about such good use of memory! ^_^ woo, so many AC codes are posted. doesn't matter my spoiling one more. #include <cstdio> #include <cstdlib> #include <cstring> using namespace std; int main (void) { int n; scanf("%d", &n); printf("%d\n", ((1 + n) * (abs(1 - n) + 1)) >> 1); return 0; } Re: it isn`t too intresting is it?!!!! i used less memory than you :D (+) How about my programme. var n:longint; begin readln(n); writeln((1+n)*(abs(n-1)+1)div 2); end. Edited by author 18.02.2006 15:12 Edited by author 18.02.2006 15:12 |
|
|