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 ...
随机推荐
- python019 Python3 File(文件) 方法
file 对象使用 open 函数来创建,下表列出了 file 对象常用的函数: 序号 方法及描述 1 file.close() 关闭文件.关闭后文件不能再进行读写操作. 2 file.flush() ...
- zoj 2807 Electrical Outlets
Electrical Outlets Time Limit: 2 Seconds Memory Limit: 65536 KB Roy has just moved into a new a ...
- [Go]结构体及其方法
结构体类型可以包含若干字段,每个字段通常都需要有确切的名字和类型.也可以不包含任何字段,这样并不是没有意义的,因为还可以为这些类型关联上一些方法,这里可以把方法看作事函数的特殊版本. 函数事独立的程序 ...
- Robot Framework中的未解之谜
今天在写测试用例的时候偶然发现了一个问题: 一.看脚本逻辑上没有问题,但是在引用变量的时候不能成功引用,脚本截图如下: 这个是关键字A的截图,没有参数. 此时在case中引用${phonesign}和 ...
- 我是一个线程 - IBM刘欣
来自:码农翻身(微信号:coderising) 作者:IBM刘欣 我是一个线程,我一出生就被编了个号: 0×3704,然后被领到一个昏暗的屋子里, 这里我发现了很多和我一模一样的同伴. 我身边的同伴0 ...
- 【BZOJ4736】温暖会指引我们前行(LCT)
题意:有一张图,每条边有一个不同的编号,长度和权值,维护以下操作: 1.加边 2.修改边长 3.询问两点之间在最小权值最大的前提下的唯一路径长度 n<=100000 m<=300000 思 ...
- 【BZOJ4517】排列计数(排列组合)
题意:1-n的一个序列,其中有m个a[i]=i,求方案数 n,m<=1000000 题意:显然ANS=c(n,m)*d[n-m] d[i]为错排方案数=d[i-1]*n+(-1)^n ; ..] ...
- msp430入门编程26
msp430中C语言开发工具应用 msp430入门学习 msp430入门编程
- 前端学习之-- JavaScript
JavaScript笔记 参考:http://www.cnblogs.com/wupeiqi/articles/5602773.html javaScript是一门独立的语言,游览器都具有js解释器 ...
- Codeforces 659B Qualifying Contest【模拟,读题】
写这道题题解的目的就是纪念一下半个小时才读懂题...英文一多读一读就溜号... 读题时还时要静下心来... 题目链接: http://codeforces.com/contest/659/proble ...