版本1和2间的区别
于2006-03-11 15:39:10修订的的版本1
大小: 531
编辑: czk
备注:
于2006-04-21 15:49:46修订的的版本2
大小: 737
编辑: czk
备注:
删除的内容标记成这样。 加入的内容标记成这样。
行号 2: 行号 2:
http://acm.timus.ru/problem.aspx?space=1&num=1068
行号 23: 行号 24:
http://acm.timus.ru/problem.aspx?space=1&num=1068
行号 26: 行号 27:
{{{#!cplusplus
#include <iostream>
using namespace std;

int main()
{
  int n;
  cin >> n;
  if(n>0) {
    cout << n*(n+1)/2 << endl;
  } else {
    cout << n*(-n+1)/2+1 << endl;
  }
}
}}}

Sum

http://acm.timus.ru/problem.aspx?space=1&num=1068

Time Limit: 2.0 second

Memory Limit: 1 000 K

Your task is to find the sum of all integer numbers lying between 1 and N inclusive.

1. Input

The input consists of a single integer N that is not greater than 10000 by it's absolute value.

2. Output

Write to the output file a single integer number that is the sum of all integer numbers lying between 1 and N inclusive.

3. Sample Input

{{{-3 }}}

4. Sample Output

{{{-5 }}}


   1 #include <iostream>
   2 using namespace std;
   3 
   4 int main()
   5 {
   6   int n;
   7   cin >> n;
   8   if(n>0) {
   9     cout << n*(n+1)/2 << endl;
  10   } else {
  11     cout << n*(-n+1)/2+1 << endl;
  12   }
  13 }

timus1068 (2008-02-23 15:36:54由localhost编辑)

ch3n2k.com | Copyright (c) 2004-2020 czk.