Codeforces Round #277 (Div. 2) A. Calculating Function 水题
2015-10-25 13:30
323 查看
A. Calculating Function
Time Limit: 20 SecMemory Limit: 256 MB
题目连接
http://codeforces.com/contest/486/problem/ADescription
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.
[b]Input[/b]
The single line contains the positive integer n (1 ≤ n ≤ 1015).
[b]Output[/b]
Print f(n) in a single line.
[b]Sample Input[/b]
4
[b]Sample Output[/b]
2
HINT
[b]题意[/b]f(n) = - 1 + 2 - 3 + .. + ( - 1)^n
给你n,然后让你求f(n)
[b]题解:[/b]
分奇偶啦,奇数就是(n-1)/2-n,偶数就是n/2
[b]代码[/b]
#include<stdio.h> #include<iostream> using namespace std; int main() { long long n;scanf("%lld",&n); if(n%2==1) printf("%lld\n",(n-1LL)/2LL - n); else printf("%lld\n",n/2LL); }
相关文章推荐
- 转:iOS-生成Bundle包-引入bundle-使用bundle
- [sicily]1636. show me the money
- 删除11.2.0.4 rac中 ora.crf的两类文件 和 禁止ora.crf随ohas启动而启动
- 1014. 福尔摩斯的约会 (20)
- 【HDOJ】3436 Queue-jumpers
- C++STL学习(10)STL算法(1)
- MVC IIS创建过程问题收录
- html5通过特殊链接:打电话,发短信,发邮件
- c语言之野指针理解
- leetcode 204 Count Prime
- Hadoop之数据仓库构建-Hive
- struts2整合jfreechart
- 凝视条件推断浏览器<!--[if !IE]><!--[if IE]><!--[if lt IE 6]><!--[if gte IE 6]>
- 3、关于利用SqlSessionFactoryBuilder去构建SqlSessionFactory,以及Mybatis的dao的实现
- HexDump
- 2013杭州站C - Zhuge Liang's Password(模拟)
- Java笔记集合之栈和队列
- spring—声明式事务管理总结
- DataProcessing
- (原创)c#学习笔记05--变量的更多内容01--类型转换01--隐式转换