Codeforces Round #277 (Div. 2)(A)模拟,打表
来源:互联网 发布:天堂js手机版下载 编辑:程序博客网 时间:2024/05/22 01:15
A. Calculating Function
time limit per test
1 secondmemory limit per test
256 megabytesinput
standard inputoutput
standard outputFor 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
- Codeforces Round #277 (Div. 2)(A)模拟,打表
- Codeforces Round #346 (Div. 2) -A. Round House(模拟)
- Codeforces Round #297 (Div. 2) A(模拟)
- Codeforces Round #340 (Div. 2)(A) 模拟
- Codeforces Round #107 (Div. 2) A(简单模拟)
- Codeforces Round #109 (Div. 2) A (简单模拟)
- Codeforces Round #281 (Div. 2)A(构造+暴力模拟)
- Codeforces Round #328 (Div. 2)Problem A. PawnChess(模拟)
- Codeforces Round #335 (Div. 2) (A)模拟
- Codeforces Round #341 (Div. 2)(A)模拟
- Codeforces Round #294 (Div. 2)(A)模拟
- Codeforces Round #246 (Div. 2)(A)模拟
- Codeforces Round #247 (Div. 2)(A)模拟
- Codeforces Round #321 (Div. 2)(A)模拟
- Codeforces Round #273 (Div. 2)(A)模拟
- Codeforces Round #345 (Div. 2)-A. Joysticks(模拟)
- Codeforces Round #346 (Div. 2)(A)模拟
- Codeforces Round #349 (Div. 2)(A)模拟
- iOS之旅--用CollectionView实现轮播图效果+封装方法
- php mysql大数据处理
- HDU 1002 A + B Problem II (JAVA大数)
- IOS开发中新特性的实现
- K--近邻算法示例
- Codeforces Round #277 (Div. 2)(A)模拟,打表
- 贝塞尔曲线精讲
- C++第1次实验
- ora-01403:未找到任何数据
- Injection for Xcode 不用build 查看效果.类似于HTML 的F5
- Node.js最新技术栈之Promise篇
- VS2015 OPENGL配置(X86平台)
- Nginx安装到使用__me
- Oracle与MySQL的几点区别