zoukankan      html  css  js  c++  java
  • cf486A Calculating Function

    A. Calculating Function
    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

    一分钟就秒了

    #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/2);
    	else printf("%lld
    ",n/2-n);
    }
    

      

    ——by zhber,转载请注明来源
  • 相关阅读:
    leetcode32 Longest Valid Parentheses 最长有效括号序列
    js的Prototype属性
    一道区间dp和一道字符串
    Cookie和Session
    JS选择器querySelector和~All,三个原生选择器
    module.exports和exports
    Windows7环境下MongoDB安装和配置
    转载:Ajax基础详解&&http填坑2
    Node后台刷评论
    Node 简单爬虫
  • 原文地址:https://www.cnblogs.com/zhber/p/4093654.html
Copyright © 2011-2022 走看看