1072 -- Sum Problem

来源:互联网 发布:域名劫持转发教程 编辑:程序博客网 时间:2024/06/06 06:54

Sum Problem

Time Limit:1000MS  Memory Limit:65536K
Total Submit:504 Accepted:268

Description

Hey, welcome to ahstu oj.

In this problem, your task is to calculate SUM(n) = 1 + 2 + 3 + ... + n.

Input

The input will consist of a series of integers n, one integer per line.

Output

For each case, output SUM(n) in one line. You may assume the result will be in the range of 32-bit signed integer.

Sample Input

1100

Sample Output

15050

Source

    using System;    using System.Collections.Generic;    using System.Linq;    using System.Text;    namespace AK1072 {        class Program {            static void Main(string[] args) {                string sb;                while ((sb = Console.ReadLine()) != null) {                    long n = long.Parse(sb);                    long sum = (1 + n) * n / 2;                    Console.WriteLine(sum);                }            }        }    }


0 0
原创粉丝点击