ACM-1001
2016-04-11 21:14
351 查看
Problem Description
Hey, welcome to HDOJ(Hangzhou Dianzi University Online Judge).
In this problem, your task is to calculate SUM(n) = 1 + 2 + 3 + ... + n.
Input
The input will consist of a series of integers n, one integer per line.
Output
For each case, output SUM(n) in one line, followed by a blank line. You may assume the result will be in the range of 32-bit signed integer.
Sample Input
Sample Output
Hey, welcome to HDOJ(Hangzhou Dianzi University Online Judge).
In this problem, your task is to calculate SUM(n) = 1 + 2 + 3 + ... + n.
Input
The input will consist of a series of integers n, one integer per line.
Output
For each case, output SUM(n) in one line, followed by a blank line. You may assume the result will be in the range of 32-bit signed integer.
Sample Input
1 100
Sample Output
1 5050 #include <iostream> #include <cstdio> using namespace std; int main() { int n,sum; while(scanf("%d",&n)!=EOF) { if(n%2==0) sum=n/2*(n+1); else sum=(n+1)/2*n; printf("%d\n\n",sum); } return 0; }
相关文章推荐
- Hadoop安全模式详解及配置
- CSS3实战之box-shadow篇
- 二分图匹配--匈牙利算法
- windows下python安装Numpy、matplotlib和whl文件
- 【POJ 3277】 City Horizon(离散化+树状数组+二分)
- tomcat——简单的日志实现
- spring applicationContext.xml 配置文件 详解
- NYOJ564 最优对称路径(记忆化搜索+spfa)
- 2016-04-11/获取系统当前时间
- 用vector进行图的邻接表存储
- linux基础学习之 nfs挂载
- Hibernate管理Session
- 重学STM32---(九) ——CAN通信(一)
- 谷歌对面试者提出的15个让人疯狂的问题
- js练习题三:使div变色 密码提示框
- 联合巨头做庄开源,英特尔在云计算时代再造DIY模式
- 设计模式基础——UML类图
- Apache CXF实现的RESTful形式的webservices
- 从设计心理学理解交互设计的原则
- 值班管理数据表设计