time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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
input
5
output
-3
Note

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

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

解题思路:大水题一枚。直接找规律。n%2==0时,f = n/2; 否则,f = -(n+1)/2.

AC代码:

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
#define INF 0x7fffffff int main()
{
// #ifdef sxk
// freopen("in.txt","r",stdin);
// #endif
long long n;
while(scanf("%lld",&n)!=EOF)
{
if(n & 1) printf("%lld\n", -(n+1)/2);
else printf("%lld\n", n/2);
}
return 0;
}

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 水

    A. Calculating Function   For a positive integer n let's define a function f: f(n) =  - 1 + 2 - 3 +  ...

  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) 题解

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

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

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

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

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

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

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

  8. 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 ...

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

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

随机推荐

  1. notepad++ 删除重复记录

    sort line with Edit -> Line Operations -> Sort Lines Lexicographically ascending do a Find / R ...

  2. 带WHERE子句的UPDATE语句

    目前演示的几个UPDATE语句都是一次性更新所有行的数据,这无法满足只更新符合特定条件的行的需求,比如“将Tom 的年龄修改为12 岁”.要实现这样的功能只要使用WHERE 子句就可以了,在WHERE ...

  3. [Codeforces 32E] Hide-and-Seek

    Brief Intro: 给两个人的坐标,一堵墙和一面镜子,询问两人能否看见对方 Solution: 一道以分类讨论为主的计算几何题, 分别讨论两人坐标连线是否经过墙/镜子即可, 难点在于如何求出点x ...

  4. CodeForces - 283E Cow Tennis Tournament

    Discription Farmer John is hosting a tennis tournament with his n cows. Each cow has a skill level s ...

  5. python3开发进阶-Django框架中form的查看校验方法is_valid()的源码,自定义验证方法

    form表单的校验方法is_valid() 点开我们发现这个函数里面只有两个方法方法,最终返回True or False 我们点进.is_bound属性,里面判断传输的数据不是空和上传文件不是空 点进 ...

  6. Exercise01_11

    public class Population{ public static void main(String[] args){ int sum,s; s=365*5*24*60*60; sum=31 ...

  7. Problem C: 零起点学算法18——3个数比较大小

    #include<stdio.h> int main() { int a,b,c; while(scanf("%d %d %d",&a,&b,& ...

  8. Linux下的echo输出换行符

    echo -e "text1\ntext2" -e表示开启转移字符

  9. JS面向对象函数的四种调用模式

    函数的四种调用模式 概念 在 js 中,无论是函数, 还是方法, 还是事件, 还是构造器,...这些东西的本质都是函数 函数, 方法, 事件, 构造器,...只是所处的位置不同 这四种模式分别是 函数 ...

  10. [原创]用逻辑嗅探破解接触式IC卡口令

    最近两周对接触型IC卡很感兴趣,就动手实践了一下,最终实现的效果是通过破解IC卡口令实现对数据修改,然后就可以随意洗衣服喽~IC卡从数据传递方式上划分为接触型和非接触型两种.接触型的卡片表面有金属贴片 ...