HDOJ 1001Sum Problem

简介: HDOJ 1001Sum Problem

Problem Description

Hey, welcome to HDOJ(Hangzhou Dianzi University Online Judge).


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, followed by a blank line. You may assume the result will be in the range of 32-bit signed integer.


Sample Input

1

100


Sample Output

1


5050


import java.util.*;
class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    while(sc.hasNext()){
      int n = sc.nextInt();
      int sum=0;
      for(int i=1;i<=n;i++)
        sum+=i;
      System.out.println(sum);
      System.out.println();
  }
  }
}
目录
相关文章
LeetCode 39. Combination Sum
给定一个无重复元素的数组 candidates 和一个目标数 target ,找出 candidates 中所有可以使数字和为 target 的组合。 candidates 中的数字可以无限制重复被选取。
75 0
LeetCode 39. Combination Sum
LeetCode 216. Combination Sum III
找出所有相加之和为 n 的 k 个数的组合。组合中只允许含有 1 - 9 的正整数,并且每种组合中不存在重复的数字。
111 0
LeetCode 216. Combination Sum III
HDOJ 2058 The sum problem
HDOJ 2058 The sum problem
118 0
HDOJ 2101 A + B Problem Too
HDOJ 2101 A + B Problem Too
112 0
HDOJ 1002 A + B Problem II
HDOJ 1002 A + B Problem II
125 0
|
Java
HDOJ 1000 A + B Problem
HDOJ 1000 A + B Problem
117 0
HDOJ(HDU) 1898 Sempr == The Best Problem Solver?(水题、、、)
HDOJ(HDU) 1898 Sempr == The Best Problem Solver?(水题、、、)
134 0
|
机器学习/深度学习
HDOJ-1001 Sum Problem
Problem Description Hey, welcome to HDOJ(Hangzhou Dianzi University Online Judge).
1264 0
|
Java 机器学习/深度学习 网络协议
HDOJ-1002 A + B Problem II
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Problem ...
1163 0

热门文章

最新文章