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. 【bzoj1455】【罗马游戏】左偏树+并查集(模板)

    Description 罗马皇帝很喜欢玩杀人游戏. 他的军队里面有n个人,每个人都是一个独立的团.最近举行了一次平面几何测试,每个人都得到了一个分数. 皇帝很喜欢平面几何,他对那些得分很低的人嗤之以鼻 ...

  2. Java高级架构师(一)第01节:整体课程概览

    本课程专注于构建:高可扩展性.高性能.大数据量.高并发.分布式的系统架构. 从零开始.全面系统.成体系的软件架构课程,循序渐进的讲述构建上述系统架构所需要的各种技术知识和技能. 适应人群: 1:有一定 ...

  3. 将js方法名作为参数传给js方法

    1,demo1:参数function无参 <script> function fun1(){ fun3('fun4'); } function fun2(){ fun3('fun5'); ...

  4. 关于GIT的一些注意点

    往空仓库提交代码之前先将文档区的_gitignore放到项目根目录然后改名成.gitignore然后git add .gitignore以上的目的是忽略一些不应该提交GIT的文件,多人编辑工程的时候不 ...

  5. Android UI Material Design

    Material Design 中文版: http://wiki.jikexueyuan.com/project/material-design/ Material Design开发文章系列1:App ...

  6. 水晶报表导出完美EXCEL表格

    水晶报表自带的导出Excel不太完美(这一点与SQL的SSRS相比就差太远了),导出的文件没有网格线,而且非常容易出现跨行跨列的现象,要做一个符合要求的报表还真要花不少的时间与精力去调试. 下面我简单 ...

  7. mysql 5.7.20解压版安装配置

    MySql 5.7.20版本免安装版配置过程   下载地址为: https://dev.mysql.com/downloads/mysql/ 最下面根据自己的操作系统选择合适的型号 下载完以后解压缩到 ...

  8. MariaDB数据库管理系统

    MYSQL数据库管理系统被Oracle公司收购后从开源换向到了封闭,导致许多Linux发行版选择了MariaDB.   MYSQL是一款大家都非常熟知的数据库管理系统,技术成熟.配置简单.开源免费并且 ...

  9. 基于Spark机器学习和实时流计算的智能推荐系统

    概要: 随着电子商务的高速发展和普及应用,个性化推荐的推荐系统已成为一个重要研究领域. 个性化推荐算法是推荐系统中最核心的技术,在很大程度上决定了电子商务推荐系统性能的优劣,决定着是否能够推荐用户真正 ...

  10. What is Continuous Integration?

    什么叫持续集成? 原文: https://docs.microsoft.com/en-us/azure/devops/what-is-continuous-integration ---------- ...