A. Calculating Function
 

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.

Sample test(s)
input
4
output
2
 
Note

f(4) =  - 1 + 2 - 3 + 4 = 2

f(5) =  - 1 + 2 - 3 + 4 - 5 =  - 3

题意:定义f(n),求f(n);

题解:奇偶关系

///
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll;
#define mem(a) memset(a,0,sizeof(a))
#define pb push_back
#define meminf(a) memset(a,127,sizeof(a)); inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){
if(ch=='-')f=-;ch=getchar();
}
while(ch>=''&&ch<=''){
x=x*+ch-'';ch=getchar();
}return x*f;
}
//****************************************
#define maxn 1000+5
#define mod 1000000007 int main(){ ll n=read();
if(n%==){
cout<<n/<<endl;
}
else {
cout<<(n-)/-n<<endl;
}
return ;
}

代码

最新文章

  1. GTX 680 Kepler
  2. 基于 OpenSSL 的 CA 建立及证书签发 【转】
  3. 《ArcGIS Engine+C#实例开发教程》第二讲 菜单的添加及其实现
  4. StrPCopy与StrPas功能正好相反,作用是与C语言字符串和Delphi的String相互转化
  5. Android中库项目、jar包等的使用方法
  6. 使用AngularJS的三个重要原因
  7. 『练手』001 Laura.SqlForever架构基础(Laura.XtraFramework 的变迁)
  8. Petrozavodsk Winter Camp, Warsaw U, 2014, A The Carpet
  9. python3下调用系统massagebox对话框
  10. (LIS DP) codeVs 1044 拦截导弹
  11. Can not deserialize instance of xxx out of START_ARRAY token
  12. 10分钟上手图数据库Neo4j
  13. python_day12_html
  14. CSS--点击改变样式
  15. Python3中的内置函数
  16. python parse xml using DOM
  17. sublime主题选择
  18. ACE接受器-连接器模式
  19. Eclipse 调试
  20. [mongodb] MMAP 和wiredTiger 的比较

热门文章

  1. 【转】Java中的String为什么是不可变的? -- String源码分析
  2. PHP基础知识测试题及解析
  3. 04--Spring知识汇总
  4. JS——event
  5. 获取qq音乐json数据---某课网音乐app学习
  6. C3P0数据库连接池使用方法
  7. Weex框架源码分析(Android)(一)
  8. Python学习笔记——Matplot库
  9. HDU-4055 Number String 动态规划 巧妙的转移
  10. Linux日期时间