Codeforces Round #277 (Div. 2)A. Calculating Function 水

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);

题解:奇偶关系

///1085422276
#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=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;
}
//****************************************
#define maxn 1000+5
#define mod 1000000007


int main(){


    ll n=read();
    if(n%2==0){
        cout<<n/2<<endl;
    }
    else {
        cout<<(n-1)/2-n<<endl;
    }
  return 0;
}
代码
原文地址:https://www.cnblogs.com/zxhl/p/4948729.html