codeforces 486A Calculating Function
来源:互联网 发布:阿里云rds逻辑备份 编辑:程序博客网 时间:2024/06/05 20:18
网址:点击打开链接
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
因为n的值过大,所以要考虑它的规律,而不是求前面的每一项。
#include<stdio.h>int main(){ __int64 n; scanf("%I64d",&n); if(n&1) printf("%I64d\n",(n-1)/2-n); else printf("%I64d\n",n/2); return 0;}
阅读全文
0 0
- codeforces 486A Calculating Function
- codeforces 486A Calculating Function
- Codeforces 486A Calculating Function(水题)
- Codeforces 486A Calculating Function(math)
- codeforces 486A(Calculating Function) Java
- 486A - Calculating Function
- 【codeforces div2 A】Calculating Function(思维)
- Codeforces Calculating Function
- A. Calculating Function
- Codeforces Round #277 (Div. 2)---A. Calculating Function (规律)
- CF 277 div2 A. Calculating Function
- Calculating Function
- 【Codeforces 840 A. Leha and Function】& 构造
- codeforces 840A Leha and Function
- Codeforces 840A Leha and Function
- Codeforces Round #150 (Div. 1) A. The Brand New Function
- Codeforces Round #136 (Div. 2) A. Little Elephant and Function
- CodeForces 243A|The Brand New Function|位运算
- 安卓打开设置界面的方法
- springmvc源码1
- c++ 设计模式4 (Strategy)
- 飞日强装修公司
- 从RGB色转为灰度色算法(转)
- codeforces 486A Calculating Function
- jquery开发:jquery事件绑定解绑机制
- 从Spark架构中透视Sparkjob
- 图片 保存 与读取
- 简单工厂模式
- leetcode— 9. Palindrome Number
- 剑指offer 1
- Android Binder机制----实现自定义的系统服务
- TCP长连接与短连接的区别