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 got AC with an 28K program!!
Posted by Drizzt 15 Mar 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 (+)
Posted by Locomotive 15 Mar 2003 08:22
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!
Posted by <P><P><P> 17 Mar 2003 01:06
^_^
woo, so many AC codes are posted. doesn't matter my spoiling one more.
Posted by Neal Zane 8 Aug 2003 12:54
#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 (+)
Posted by zhangwuji 18 Feb 2006 15:11
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