设为首页 加入收藏

TOP

NYOJ-sum of all integer numbers
2015-07-20 17:47:37 来源: 作者: 【 】 浏览:1
Tags:NYOJ-sum all integer numbers

sum of all integer numbers

时间限制:1000 ms | 内存限制:65535 KB 难度:0
描述
Your task is to find the sum of all integer numbers lying between 1 and N inclusive.
输入
There are multiple test cases.
The input consists of a single integer N that is not greater than 10000 by it's absolute value.
输出
Write a single integer number that is the sum of all integer numbers lying between 1 and N inclusive.
样例输入
3
样例输出
6

代码:

#include
      
       
#include
       
         int main() { int n; while(~scanf("%d",&n)) { if(n==0) { printf("1\n"); continue; } int k=1,t=0; if(n<0) k=-1,t=1; n=abs(n); if(n&1) printf("%d\n",((n+1)>>1)*n*k+t); else printf("%d\n",(n>>1)*(n+1)*k+t); } return 0; }
       
      


<script type="text/java script">
<script type="text/java script">BAIDU_CLB_fillSlot("771048");
点击复制链接 与好友分享! 回本站首页
<script> function copyToClipBoard(){ var clipBoardContent=document.title + '\r\n' + document.location; clipBoardContent+='\r\n'; window.clipboardData.setData("Text",clipBoardContent); alert("恭喜您!复制成功"); }
<script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"24"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];
您对本文章有什么意见或着疑问吗?请到 论坛讨论您的关注和建议是我们前行的参考和动力??
上一篇: UVA 12167 - Proving Equivalences(强连通分量+缩点)
下一篇: BNU25359Escape Time II(状态压缩DP)
相关文章
解决C/C++中的multiple definition
深入谈谈C/C++的sizeof( )的计算(指
<script type="text/java script">BAIDU_CLB_fillSlot("182716");
<script type="text/java script">BAIDU_CLB_fillSlot("517916");
图文推荐
<script> (function(){ var appid = 'cyrBEfE7C', conf = 'prod_830794cf494da8b808afb2994cfe0fee'; var doc = document, s = doc.createElement('script'), h = doc.getElementsByTagName('head')[0] || doc.head || doc.documentElement; s.type = 'text/java script'; s.charset = 'utf-8'; s.src = 'http://assets.changyan.sohu.com/upload/changyan.js?conf='+ conf +'&appid=' + appid; h.insertBefore(s,h.firstChild); window.SCS_NO_IFRAME = true; })()
<script type="text/java script">BAIDU_CLB_fillSlot("771057");
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇UVA 12167 - Proving Equivalence.. 下一篇UVA 10054 The Necklace

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·Python中文网 - 人生 (2025-12-24 18:49:47)
·【整整648集】这绝对 (2025-12-24 18:49:44)
·Python超详细一条龙 (2025-12-24 18:49:42)
·【超详细】JDK 下载 (2025-12-24 18:19:32)
·Java_百度百科 (2025-12-24 18:19:29)