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;
}
YTU 2905: The Sum of 1...N的更多相关文章
- 如何在web中实现类似excel的表格控件
Execl功能非常强大,内置的很多函数或公式可以大大提高对数据的加工处理能力.那么在web中有没有类似的控件呢?经过一番搜寻,发现handsontable具备了基本的excel功能支持公式,同时能对数 ...
- LeetCode - Two Sum
Two Sum 題目連結 官網題目說明: 解法: 從給定的一組值內找出第一組兩數相加剛好等於給定的目標值,暴力解很簡單(只會這樣= =),兩個迴圈,只要找到相加的值就跳出. /// <summa ...
- Leetcode 笔记 113 - Path Sum II
题目链接:Path Sum II | LeetCode OJ Given a binary tree and a sum, find all root-to-leaf paths where each ...
- Leetcode 笔记 112 - Path Sum
题目链接:Path Sum | LeetCode OJ Given a binary tree and a sum, determine if the tree has a root-to-leaf ...
- POJ 2739. Sum of Consecutive Prime Numbers
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20050 ...
- BZOJ 3944 Sum
题目链接:Sum 嗯--不要在意--我发这篇博客只是为了保存一下杜教筛的板子的-- 你说你不会杜教筛?有一篇博客写的很好,看完应该就会了-- 这道题就是杜教筛板子题,也没什么好讲的-- 下面贴代码(不 ...
- [LeetCode] Path Sum III 二叉树的路径和之三
You are given a binary tree in which each node contains an integer value. Find the number of paths t ...
- [LeetCode] Partition Equal Subset Sum 相同子集和分割
Given a non-empty array containing only positive integers, find if the array can be partitioned into ...
- [LeetCode] Split Array Largest Sum 分割数组的最大值
Given an array which consists of non-negative integers and an integer m, you can split the array int ...
随机推荐
- Struts2执行原理
[原理图] [MVC] [执行过程(重要!!!!!)] 1) 客户端浏览器发出请求时,被Tomcat服务器所接收.Tomcat容器将用户的请求封装为HttpServletRequest对象 2) 请求 ...
- shell if判断总结
一.if的基本语法: if [ command ];then 符合该条件执行的语句 elif [ command ];then 符合该条件执行的语句 else 符合该条件执行的语句 ...
- Leetcode 297.二叉树的序列化和反序列化
二叉树地序列化和反序列化 序列化是将一个数据结构或者对象转换为连续的比特位的操作,进而可以将转换后的数据存储在一个文件或者内存中,同时也可以通过网络传输到另一个计算机环境,采取相反方式重构得到原数据. ...
- Leetcode 229.求众数II
求众数II 给定一个大小为 n 的数组,找出其中所有出现超过 ⌊ n/3 ⌋ 次的元素. 说明: 要求算法的时间复杂度为 O(n),空间复杂度为 O(1). 示例 1: 输入: [3,2,3] 输出: ...
- 查看java进程中哪个线程在消耗系统资源
1 top -p $pid -H 加上-H这个参数后,会列出有哪些线程.这样就可以看到哪个线程id最消耗系统资源了.看到的线程id是10进制的数字. 2 jstack $pid 可以打印出制定jav ...
- [转]ORA-38500: USING CURRENT LOGFILE option not available without stand
标签: oracle 10g 数据库 ora-38500 it 分类: IT author:skate time :2009/08/03 在dataguard启用实时恢复的时候,报如下错误: ORA- ...
- RPC实现的底层原理及应用
摘要:RPC(Remote Procedure Call Protocol)——远程过程调用协议,它是一种通过网络从远程计算机程序上请求服务,而不需要了解底层网络技术的协议.RPC协议假定某些传输协议 ...
- SGU515:Recover path 【最短路】
警告:这题卡SPFA,警告:这题卡SPFA 这不是演习 题目大意:给出一个无向图,以及一些点的序列,要找出一条最短的路径使得通过所有点,题目保证存在一条头尾都在点的序列中的最短路满足题意 思路:没有最 ...
- 【dp】HDU 1421 搬寝室
http://acm.hdu.edu.cn/showproblem.php?pid=1421 [题意] 给定n个数,要从n个数中选择k个二元组{x,y},最小化sum{(x-y)^2} 2<=2 ...
- webmagic使用手册
https://my.oschina.net/flashsword/blog/180623 重点 SeleniumDownloader 对于一些Javascript动态加载的网页,仅仅使用http模拟 ...