#CCBCHBA0000015. Tổng từ 1 đến n (Sum from 1 to N)
Tổng từ 1 đến n (Sum from 1 to N)
Sum from 1 to N
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem Statement
Given nonnegative n, compute 1+2+...+n. For n=0 the sum is zero. Practice accumulation in a for loop and signed 64-bit arithmetic.
Input
One integer n.
Output
One integer representing the sum.
Subtasks
- Subtask 1 (20%): .
- Subtask 2 (30%): .
- Subtask 3 (50%): .
Examples
Example 1
Input
5
Output
15
Explanation
0+1+2+3+4+5=15.
Example 2
Input
0
Output
0
Explanation
The loop runs zero times, leaving the sum at zero.