YTU 2905: The Sum of 1...N
2905: The Sum of 1...N
时间限制: 1 Sec 内存限制: 128 MB提交: 281 解决: 51
题目描述
Given an integer n,your task is to calculate 1+2+...+N;
输入
The first line of input contains an integer T, indicating the number of test cases (T<=20)
The each test case contains a single positive integer N(N<=2^32).
输出
For each input you should output the sum of 1+2+...+N in one line.(The result must less than 2^63)
样例输入
2101
样例输出
551
im0qianqian_站在回忆的河边看着摇晃的渡船终年无声地摆渡,它们就这样安静地画下黄昏画下清晨......![可怜]()
#include <iostream>
using namespace std;
int main()
{
unsigned long long n;
int T;
cin>>T;
while(T--)
{
cin>>n;
n=n*(n+1)/2;
cout<<n<<endl;
}
return 0;
}
------------------- 这是千千的个人网站哦! https://www.dreamwings.cn -------------------


浙公网安备 33010602011771号