Codeforces Round #277 (Div. 2)(A)模拟,打表

来源:互联网 发布:天堂js手机版下载 编辑:程序博客网 时间:2024/05/22 01:15

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.

Examples
input
4
output
2
input
5
output
-3
Note

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

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



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


题解:打个表,找下规律输出就好了



#include<cstdio>  #include<cstring>  #include<cstdlib>  #include<cmath>  #include<iostream>  #include<algorithm>  #include<vector>  #include<map>  #include<set>  #include<queue>  #include<string>  #include<bitset>  #include<utility>  #include<functional>  #include<iomanip>  #include<sstream>  #include<ctime>  using namespace std;#define N int(1e5)  #define inf int(0x3f3f3f3f)  #define mod int(1e9+7)  typedef long long LL;#if ( ( _WIN32 || __WIN32__ ) && __cplusplus < 201103L)  #define lld "%I64d"  #else  #define lld "%lld"  #endif  #ifdef CDZSC  #define debug(...) fprintf(stderr, __VA_ARGS__)  #else  #define debug(...)   #endif  int main(){#ifdef CDZSC  freopen("i.txt", "r", stdin);//freopen("o.txt","w",stdout);  int _time_jc = clock();#endif  LL n;while (~scanf("%lld", &n)){printf("%lld\n", (n & 1) ? -(n + 1) / 2 : n / 2);}#ifdef CDZSC  debug("time: %d\n", int(clock() - _time_jc));#endif  return 0;}







0 0