B - Calculating Function
2024-08-31 06:58:24
Problem description
For a positive integer n let's define a function f:
f(n) = - 1 + 2 - 3 + .. + ( - 1)nn
Your task is to calculate f(n) for a given integer n.
Input
The single line contains the positive integer n (1 ≤ n ≤ 1015).
Output
Print f(n) in a single line.
Examples
Input
4
Output
2
Input
5
Output
-3
Note
f(4) = - 1 + 2 - 3 + 4 = 2
f(5) = - 1 + 2 - 3 + 4 - 5 = - 3
解题思路:简单求前n项和,分为奇数和偶数两种情况,水过!
AC代码:
#include <bits/stdc++.h>
using namespace std;
int main(){
long long n;
cin>>n;
if(n&)cout<<(n/-n)<<endl;
else cout<<(n/)<<endl;
return ;
}
最新文章
- 【AutoMapper官方文档】DTO与Domin Model相互转换(中)
- AndroidStudio里面怎么取消与SVN的关联
- iOS 中的字体预览
- 线程入门之实现Runnable接口和继承Thread类
- iOS - OC NSNull		空值
- 可滑动的ToggleButton(开关)
- CCS5 编译器手动设置dsp支持可变参数宏等问题
- 量化生产力Quantifying Productivity
- http响应Last-Modified和ETag(转)
- iOS 将图片保存到本地
- HTML的基本介绍
- Android逆向分析(2) APK的打包与安装背后的故事
- dataTable tab栏切换时错位解决办法
- PermissionDispatcher 运行时权限框架
- 给 datepicker 设定日期格式
- Windows Server 2012 RS 配置IIS8.0+发布网站
- cocos2d-x 开发用到的工具
- Linux命令之rz命令与sz命令
- _spellmod_on_learn、_spellmod_on_remove
- C#基础篇七类和静态成员
热门文章
- CNN结构:用于检测的CNN结构进化-结合式方法
- AI.框架理论.语义网.语言间距.孤单
- tomcat映射java目录 sever.xml
- BZOJ 1705: [Usaco2007 Nov]Telephone Wire 架设电话线 DP + 优化 + 推导
- SharePoint Designer 2013 开启新式验证(Modern Authentication)
- Java 实现邮件发送功能
- tornado服务器运行django应用
- 编码的由来,ASCII编码,和字节的形成
- C#--线程池与线程的种类
- java.lang.AbstractMethodError: org.apache.xerces.dom.DocumentImpl.getXmlStandalone()Z解决办法