HD1001
来源:互联网 发布:海王星2.0软件下载 编辑:程序博客网 时间:2024/05/16 19:00
第一种AC,第二种可能会造成溢出。
解题关键点:
1、注意溢出,应先判断奇偶
2、 the range of32-bit signed integer。32位符号有效范围
3、样例中输出是隔行的
Sum Problem
Time Limit: 1000/500 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 266380 Accepted Submission(s): 66255Problem 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
1100
Sample Output
15050#include <iostream>using namespace std;int main(){int a;while(cin>>a){if(a%2==0)cout<<a/2*(a+1)<<endl<<endl;elsecout<<(1+a)/2*a<<endl<<endl;}return 0;}
0 0
- hd1001
- HD1001
- HD1001
- Hd1001
- HD1001 sum--20140722
- HD1001 java版答案
- 虐人的hd1001 Sum Problem
- 如何添加扩展程序(到chrome
- org.apache.hadoop.hdfs.server.datanode.DataNode: Block pool <registering> (storage id unknown) servi
- 数独
- UVa 1329 Corporative Network(带权并查集)
- android应用上传至各应用平台(1)
- HD1001
- 科研中常用到的工具
- 编译原理-语法分析器-总结
- 记一下ADC一些关键指标的计算
- c++ RTTI(运行时类型识别)
- uva 1530 - Floating Point Numbers(数论)
- 《梦断代码》摘录及感悟
- 吉他笔记 solo 和弦 推弦 音程
- 黑马程序员_Java基础[11]_单列设计模式