码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-11-09 01:24:58      阅读:160      评论:0      收藏:0      [点我收藏+]

标签:

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;
}
代码

 

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

标签:

原文地址:http://www.cnblogs.com/zxhl/p/4948729.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!