博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
cf486A Calculating Function
阅读量:4677 次
发布时间:2019-06-09

本文共 1176 字,大约阅读时间需要 3 分钟。

A. Calculating Function
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

 

一分钟就秒了

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define LL long long#define inf 0x7ffffff#define pa pair
#define pi 3.1415926535897932384626433832795028841971using namespace std;inline LL read(){ LL x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f;}int main(){ LL n=read(); if (!(n&1))printf("%lld\n",n/2); else printf("%lld\n",n/2-n);}

  

转载于:https://www.cnblogs.com/zhber/p/4093654.html

你可能感兴趣的文章
selenium常用方法
查看>>
第二次作业
查看>>
ios 面试题
查看>>
express细节点注意
查看>>
MySQL教程(二)—— 关于在ACCESS中使用SQL语句
查看>>
实验4.1
查看>>
接口Interface
查看>>
bzoj 1651: [Usaco2006 Feb]Stall Reservations 专用牛棚【贪心+堆||差分】
查看>>
bzoj 1710: [Usaco2007 Open]Cheappal 廉价回文【区间dp】
查看>>
电商:购物车模块解决思路
查看>>
Java中的Map List Set等集合类
查看>>
大道至简阅读笔记01
查看>>
多个模块使用python logging
查看>>
Linux高级变量
查看>>
php ffmpeg
查看>>
java中== 和 .equals()的区别
查看>>
网络流学习笔记
查看>>
让我们一起Go(二)
查看>>
Linq 中按照多个值进行分组(GroupBy)
查看>>
jquery validate
查看>>