time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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
input
5
output
-3
Note

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

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

解题思路:大水题一枚。直接找规律。n%2==0时,f = n/2; 否则,f = -(n+1)/2.

AC代码:

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
#define INF 0x7fffffff int main()
{
// #ifdef sxk
// freopen("in.txt","r",stdin);
// #endif
long long n;
while(scanf("%lld",&n)!=EOF)
{
if(n & 1) printf("%lld\n", -(n+1)/2);
else printf("%lld\n", n/2);
}
return 0;
}

最新文章

  1. 实现了一个百度首页的彩蛋——CSS3 Animation简介
  2. 1031MySQL事务隔离级别详解
  3. Nde模块篇
  4. Hadoop学习笔记: HDFS
  5. A Tour of Go Function closures
  6. Linux上安装JDK环境变量配置
  7. 07_Java8新增的Lambda表达式
  8. HW5.2
  9. [原博客] POI系列(1)
  10. oracle 计算两个时间之间的月份差,相差几个星期,相差多少天
  11. Android ImageButton Example 图片按钮
  12. 【原创】构建高性能ASP.NET站点之二 优化HTTP请求(前端)
  13. 张高兴的 Xamarin.Android 学习笔记:(一)环境配置
  14. 在Ubuntu下安装OpenJDK的方法
  15. Python 字符串大小写转换
  16. 痞子衡嵌入式:第一本Git命令教程(7.1)- 清理之缓存(stash)
  17. Logstash使用介绍
  18. 翻译:非递归CTE(已提交到MariaDB官方手册)
  19. python pytz时区设置模块
  20. innobackupex per table

热门文章

  1. [Codeforces 17C] Balance
  2. 【kruscal】【最小生成树】【离线】洛谷 P2266 爱的距离
  3. 6.1(java学习笔记)File类
  4. 由SequenceFile.Writer(key,value)谈toString()方法
  5. 如何提高码农产量,基于ASP.NET MVC的敏捷开发框架之自定义表单开发随笔四
  6. 【java】File的使用:将字符串写出到本地文件,大小0kb的原因
  7. firefox dispatchevent的问题
  8. ubuntu查看系统版本
  9. solr6.6 solrJ索引富文本(word/pdf)文件
  10. android中实现内容搜索