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 ...
随机推荐
- 【Codeforces 827B】High Load
[链接] 我是链接,点我呀:) [题意] 题意 [题解] 树的最长链是一定会经过两个叶子节点的. 我们可以构造一棵树,让最后的最长链一定是由经过根节点的两条链组成. 然后让这两条链的长度尽可能短就好. ...
- C#窗体学生成绩管理系统
c#学生成绩管理系统 实现用户登录.注册 所有成绩查询.个人成绩查询 管理员审核.添加.删除用户 项目源码GIT:https://github.com/soulsjie/StuScoreMa.git
- PTA 01-复杂度1 最大子列和问题 (20分)
题目地址 https://pta.patest.cn/pta/test/15/exam/4/question/709 5-1 最大子列和问题 (20分) 给定KK个整数组成的序列{ N_1N1 ...
- [BZOJ4207]Can
[BZOJ4207]Can 试题描述 这个问题是源于一个在棋盘上玩的,由Sid Sackson设计的名叫Can't stop的游戏的.这个问题与Can't stop有一定的相似之处,但是不需要玩过Ca ...
- Python基础教程笔记——第2章:列表和元组
python shell 里重复上一次的命令:Alt+p 2.3 列表:Python的苦力 (1)list函数 (2)列表赋值,不蹦蹦为一个元素不存在的位置赋值 (3)删除元素,del name[1] ...
- WKWebView的了解
1. http://blog.csdn.net/chenyong05314/article/details/53735215 2. http://www.jianshu.com/p/6ba250744 ...
- django学习之- 信号
- Django内置的信号Model signals pre_init # django的modal执行其构造方法前,自动触发 post_init # django的modal执行其构造方法后,自动触 ...
- Spring Cloud(9):Config配置中心
Config配置中心作用简单来讲:统一配置,方便管理 开源配置中心: 1.百度Disconf 2.阿里Diamand 3.Spring Cloud Config 搭建Config-Server 快速上 ...
- 一次mysql 优化 (Using temporary ; Using filesort)
遇到一个SQL执行很慢 SQL 如下: SELECT ... FROM tableA WHERE time >= 1492044535 and time <= 1492046335 GRO ...
- 附加数据库时,提示“Microsoft SQL Server,错误: 5120”, 解决方案
错误的提示内容为: