cf486A 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.
The single line contains the positive integer n (1 ≤ n ≤ 1015).
Print f(n) in a single line.
4
2
5
-3
f(4) = - 1 + 2 - 3 + 4 = 2
f(5) = - 1 + 2 - 3 + 4 - 5 = - 3
一分钟就秒了
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<ctime>
#define LL long long
#define inf 0x7ffffff
#define pa pair<int,int>
#define pi 3.1415926535897932384626433832795028841971
using namespace std;
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;
}
int main()
{LL n=read();if (!(n&1))printf("%lld\n",n/2);else printf("%lld\n",n/2-n);
}
转载于:https://www.cnblogs.com/zhber/p/4093654.html
cf486A Calculating Function相关推荐
- Codeforces Round #277 (Div. 2) A. Calculating Function 水题
A. Calculating Function Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/4 ...
- B - Calculating Function
Problem description For a positive integer n let's define a function f: f(n) = - 1 + 2 - 3 + .. + ( ...
- ACM团队周赛题解(2)
拉了CF583和CF486的两套div2题目 还是先贴宏定义部分 #define MAXN 1000000+5 #define MOD 1000000007 #define PI (acos(-1.0 ...
- Codeforces Round #277 (Div. 2) 题解
Codeforces Round #277 (Div. 2) A. Calculating Function time limit per test 1 second memory limit per ...
- Codeforces Round #277(Div 2) A、B、C、D、E题解
转载请注明出处: http://www.cnblogs.com/fraud/ --by fraud A. Calculating Function 水题,判个奇偶即可 1 #inc ...
- 动态编程语言静态编程语言_什么是动态编程?
动态编程语言静态编程语言 介绍 (Introduction) Today in this tutorial, we are going to discuss the concept of Dynami ...
- matlab bootstrap,非参数bootstrap方法和其MATLAB实现_吴庆平.pdf
第34卷第2期第34卷第2期 丽丽 水水 学学 院院 学学 报报 2012年4月2012年4月 Vo1.34Vo1.34 No.2No.2 JOURNALJOURNAL OFOF LISHUILISH ...
- 怎样设计解开数独游戏
很早之前大概是2014年的时候,我用WPF就是C#啦,写了一个数独游戏,那时之所以有这个想法,主要还是因为更早之前玩数独游戏时基本没有把题目解出,有点小受伤,但本葛葛毕竟是程序员啊,我解不出,可以用程 ...
- python做电磁场计算_加速Python中的计算(模拟磁场中的粒子)
用Python编写的程序速度有问题.该程序是"模拟磁场中的铁磁颗粒",更具体地说是磁惰性液体.该程序可以工作,但与用C ++编写的相同程序相比非常缓慢,但是我用Python编写了一 ...
最新文章
- 清华自研深度学习框架「计图」开源!多项任务性能超过PyTorch
- JavaScript编程:文档对象模型DOM
- 2015-2016 ACM-ICPC Southwestern Europe Regional Contest (SWERC 15)
- Boost:双图bimap与双向地图的测试程序
- DHCP服务器-配置
- H.264学习--1
- Android 打造完美的侧滑菜单/侧滑View控件
- Linux安装RabbitMQ及问题
- 15 年经验专家解读 IIoT 的挑战及应对思路!
- 从Demo到Engine(二) -- Render Queue Sort
- Redhat6.5中搭建Postfix邮件系统
- sql的执行顺序(from平凡世界)
- k-d Tree及其Java实现
- 24套JAVA企业实战项目教程资源分享
- 文通车牌识别 SDK
- 嘉腾发布“守护者I”抗疫机器人
- 如何从课堂派上扒取直播视频
- App接入微信登录 步骤
- mac os 录屏快捷键_Mac录屏软件集合,自带不够专业来凑
- 计算机思维培训心得,2020参加计算机培训心得体会精选
热门文章
- java中参数“ ...“的用法和意思
- supermap许可 (*.lic9d)
- Kotlin入门(22)适配器的简单优化
- mysql hibernate 延迟_在mysql数据库中,hibernate一对多的集合的延迟加载无效
- swoole task 异步任务 注释请忽略 自己加的不一定对 别误导大家。。。。。。
- VARA2015隆重召开 蔡晶晶当选CISP十大杰出人物
- JS中var、let、const区别? 用3句话概括
- redis---中文文档
- Eclipse SVN修改用户名和密码
- 一个经典编程面试题的“隐退”