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
  1. 4
output
  1. 2
 
Note

f(4) =  - 1 + 2 - 3 + 4 = 2

f(5) =  - 1 + 2 - 3 + 4 - 5 =  - 3

题意:定义f(n),求f(n);

题解:奇偶关系

  1. ///
  2. #include<bits/stdc++.h>
  3. using namespace std ;
  4. typedef long long ll;
  5. #define mem(a) memset(a,0,sizeof(a))
  6. #define pb push_back
  7. #define meminf(a) memset(a,127,sizeof(a));
  8.  
  9. inline ll read()
  10. {
  11. ll x=,f=;char ch=getchar();
  12. while(ch<''||ch>''){
  13. if(ch=='-')f=-;ch=getchar();
  14. }
  15. while(ch>=''&&ch<=''){
  16. x=x*+ch-'';ch=getchar();
  17. }return x*f;
  18. }
  19. //****************************************
  20. #define maxn 1000+5
  21. #define mod 1000000007
  22.  
  23. int main(){
  24.  
  25. ll n=read();
  26. if(n%==){
  27. cout<<n/<<endl;
  28. }
  29. else {
  30. cout<<(n-)/-n<<endl;
  31. }
  32. return ;
  33. }

代码

Codeforces Round #277 (Div. 2)A. Calculating Function 水的更多相关文章

  1. Codeforces Round #277 (Div. 2) A. Calculating Function 水题

    A. Calculating Function Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/4 ...

  2. Codeforces Round #277 (Div. 2)---A. Calculating Function (规律)

    Calculating Function time limit per test 1 second memory limit per test 256 megabytes input standard ...

  3. codeforces水题100道 第十题 Codeforces Round #277 (Div. 2) A. Calculating Function (math)

    题目链接:www.codeforces.com/problemset/problem/486/A题意:求表达式f(n)的值.(f(n)的表述见题目)C++代码: #include <iostre ...

  4. Codeforces Round #277 (Div. 2) A B C 水 模拟 贪心

    A. Calculating Function time limit per test 1 second memory limit per test 256 megabytes input stand ...

  5. Codeforces Round #277 (Div. 2) 题解

    Codeforces Round #277 (Div. 2) A. Calculating Function time limit per test 1 second memory limit per ...

  6. 【codeforces】Codeforces Round #277 (Div. 2) 解读

    门户:Codeforces Round #277 (Div. 2) 486A. Calculating Function 裸公式= = #include <cstdio> #include ...

  7. 贪心+构造 Codeforces Round #277 (Div. 2) C. Palindrome Transformation

    题目传送门 /* 贪心+构造:因为是对称的,可以全都左一半考虑,过程很简单,但是能想到就很难了 */ /************************************************ ...

  8. Codeforces Round #277 (Div. 2) 解题报告

    题目地址:http://codeforces.com/contest/486 A题.Calculating Function 奇偶性判断,简单推导公式. #include<cstdio> ...

  9. 套题 Codeforces Round #277 (Div. 2)

    A. Calculating Function 水题,分奇数偶数处理一下就好了 #include<stdio.h> #include<iostream> using names ...

随机推荐

  1. xcode常用的快捷键

    按键 描述 command+[ 左移代码块 command+] 右移代码块 Tab键 接受代码自动完成提示 Esc键 显示代码提示菜单 command+方向left键 移动光标到本行行首 comman ...

  2. Java_注解之二

    在上一次的注解案例里面配置注解的同时,也添加了一对多(@OneToMany)的关系在里面. 本次将补充上次的缺失:其他三种关联方式的配置. 为了简化配置的复杂度   在此案例中Emp和Dept并不是唯 ...

  3. 【转】Java 集合系列02之 Collection架构

    概要 首先,我们对Collection进行说明.下面先看看Collection的一些框架类的关系图: Collection是一个接口,它主要的两个分支是:List 和 Set. List和Set都是接 ...

  4. 安卓socket 心跳和信鸽自定义提示音

    /** * 连接socket 和心跳 */ public class SocketService extends Service { private static addNewOrderInterfa ...

  5. 开发日记(项目中SQL查询的优化)

    今天发现自己之前写的一些SQL查询在执行效率方面非常不理想,于是尝试做了些改进. 需求为查询国地税表和税源表中,国税有而税源没有的条目数,之前的查询如下: SELECT COUNT(NAME)     ...

  6. 深入浅出的 SQL Server 查询优化

    目前网络数据库的应用已经成为最为广泛的应用之一了,并且关于数据库的安全性,性能都是企业最为关心的事情.数据库渐渐成为企业的命脉,优化查询就解决了每个关于数据库应用的性能问题,在这里microsoft ...

  7. spring 将配置文件中的值注入 属性

    1.编写配置文件 #债权转让 #默认周期 必须大于0 credit.defaultDuration=1 #最小转让金额(元) credit.minBidAmount=1.00 #最小转让时间 到期时间 ...

  8. dotnetnuke 添加用户属性 Profile

    if (DotNetNuke.Entities.Profile.ProfileController.GetPropertyDefinitionByName(this.PortalId, "Q ...

  9. JQuery文档加载完成执行js的几种方法

    js中文档加载完毕.一般在body加一个onload事件或者window.onload = function () {} jQuery中有好多写法,平时也不注意,别人一问,还真觉得头大. 下面是我整理 ...

  10. Redis 之服务器集群配置

    常见的集群架构如图: redis操作过程中数据同步的函数调用关系: 集群搭建: 1.修改3个redis.config 文件的: 2.启动2个redis服务器 当杀掉redis主进程Master时,由于 ...