URAL 1068. Sum (小学数学题)
来源:互联网 发布:plc编程器 编辑:程序博客网 时间:2024/05/02 00:34
1068. Sum
Time limit: 2.0 second
Memory limit: 64 MB
Memory limit: 64 MB
Your task is to find the sum of all integer numbers lying between 1 and N inclusive.
Input
The input consists of a single integer N that is not greater than 10000 by it's absolute value.
Output
Write a single integer number that is the sum of all integer numbers lying between 1 and Ninclusive.
Sample
-3
-5
题意:给一个整数N,求1~N的连续和。
解析:N可正可负。
AC代码:
#include <cstdio>int main(){ int n, sum; while(scanf("%d", &n)==1){ sum = 0; if(n < 1) sum = n*(1 - n)/2 + 1; else sum = n*(n+1)/2; printf("%d\n", sum); } return 0;}
0 0
- URAL 1068. Sum (小学数学题)
- URAL 1567. SMS-spam (小学数学题)
- URAL 2001 Mathematicians and Berries (小学数学题)
- 小学数学题
- 小学数学题一道
- 一道小学的数学题
- 小学数学题 洛谷p2921
- URAL 1068. Sum
- Ural-1068. Sum(水题)
- 【Ural】1066 数学题 Garland
- URAL 1515 Cashmaster 数学题
- 小学数学题,看看现在还会做吗?
- 一道小学数学题[状元蹄]
- 传说中的越南小学数学题
- 坑爹的小学数学题
- hdoj1049 Climbing Worm(小学数学题)
- hdu 4961 Boring Sum(数学题)
- hdu 2058 The sum problem(数学题)
- OC-局部变量和全局变量、结构体、预处理指令以及关键字的基本使用
- 深入理解JAVA的多态性
- 自己看的和整理的一些经典技术博客列表BLOG
- C++学习笔记
- JS拖动效果实现
- URAL 1068. Sum (小学数学题)
- android的Bitmap和Drawable用法
- This Android SDK requires Andriod Developer Toolkit version 20.0.0 or above
- hdu-4513 吉哥系列故事——完美队形II 【Manacher】
- Tomcat Web Application Manager 如何进入
- opencv模拟景深效果
- file和page cache 的一些事儿
- struts2 iterator标签status属性
- hdu2566 统计硬币(枚举法||母函数)