HDU
来源:互联网 发布:淘宝退换货说明怎么写 编辑:程序博客网 时间:2024/05/19 15:40
Sum Problem HDU - 1001
Problem
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
ps:仔细看样例,注意用数学公式
代码如下:
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<string.h> using namespace std; int main() { long long n, sum; while(~scanf("%lld", &n)) { sum = (1+n)*n/2; //求和公式 printf("%lld\n\n", sum); //输出后还有一行 } return 0;}
阅读全文
0 0
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- HDU
- HDU
- hdu
- hdu
- HDU
- Hdu
- hdu
- hdu-
- hdu
- hdu
- hdu
- HDU
- 多写一个公式就会吓跑一半读者
- iOS 开发者开发证书和发布证书的区别以及更换的方法
- jsp
- 数据库大量字段涉及运算的javabean解决方案
- Python廖雪峰实战web开发(Day8-构建前端)
- HDU
- 算法设计与分析
- string、stringbuilder、stringbuffer区别
- Writing your first Django app, part 1
- slf4j-api、slf4j-log4j12以及log4j之间什么关系?
- “VMware Workstation 不可恢复错误:(vcpu-0)”的解决方案
- sysctl arp_filter 的作用
- OkHttp网络请求框架入门(一)
- 设计模式之策略模式