Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/486/problem/A

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.

Sample Input

4

Sample Output

2

HINT

 

题意
f(n) =  - 1 + 2 - 3 + .. + ( - 1)^n

给你n,然后让你求f(n)

题解:

分奇偶啦,奇数就是(n-1)/2-n,偶数就是n/2

代码

 

#include<stdio.h>
#include<iostream>
using namespace std;
int main()
{
    long long n;scanf("%lld",&n);
    if(n%2==1) printf("%lld\n",(n-1LL)/2LL - n);
    else printf("%lld\n",n/2LL);
}

 

相关文章:

  • 2021-08-05
  • 2022-03-05
  • 2021-06-22
  • 2021-09-20
  • 2021-12-11
  • 2021-07-17
  • 2021-07-24
  • 2022-12-23
猜你喜欢
  • 2021-09-18
  • 2021-08-28
  • 2022-12-23
  • 2021-11-09
  • 2022-12-23
  • 2022-12-23
  • 2021-07-03
相关资源
相似解决方案