Codeforces Round #277 (Div. 2)A. Calculating Function 水
2024-09-07 01:47:11
A. 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.
Input
The single line contains the positive integer n (1 ≤ n ≤ 1015).
Output
Print f(n) in a single line.
Sample test(s)
input
4
output
2
Note
f(4) = - 1 + 2 - 3 + 4 = 2
f(5) = - 1 + 2 - 3 + 4 - 5 = - 3
题意:定义f(n),求f(n);
题解:奇偶关系
///
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll;
#define mem(a) memset(a,0,sizeof(a))
#define pb push_back
#define meminf(a) memset(a,127,sizeof(a)); inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){
if(ch=='-')f=-;ch=getchar();
}
while(ch>=''&&ch<=''){
x=x*+ch-'';ch=getchar();
}return x*f;
}
//****************************************
#define maxn 1000+5
#define mod 1000000007 int main(){ ll n=read();
if(n%==){
cout<<n/<<endl;
}
else {
cout<<(n-)/-n<<endl;
}
return ;
}
代码
最新文章
- GTX 680 Kepler
- 基于 OpenSSL 的 CA 建立及证书签发 【转】
- 《ArcGIS Engine+C#实例开发教程》第二讲 菜单的添加及其实现
- StrPCopy与StrPas功能正好相反,作用是与C语言字符串和Delphi的String相互转化
- Android中库项目、jar包等的使用方法
- 使用AngularJS的三个重要原因
- 『练手』001 Laura.SqlForever架构基础(Laura.XtraFramework 的变迁)
- Petrozavodsk Winter Camp, Warsaw U, 2014, A The Carpet
- python3下调用系统massagebox对话框
- (LIS DP) codeVs 1044 拦截导弹
- Can not deserialize instance of xxx out of START_ARRAY token
- 10分钟上手图数据库Neo4j
- python_day12_html
- CSS--点击改变样式
- Python3中的内置函数
- python parse xml using DOM
- sublime主题选择
- ACE接受器-连接器模式
- Eclipse 调试
- [mongodb] MMAP 和wiredTiger 的比较