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,转载请注明来源
  • 相关阅读:
    二分图最大匹配(匈牙利算法) POJ 3041 Asteroids
    贪心 FZU 2013 A short problem
    数学 FZU 2074 Number of methods
    莫队算法/二分查找 FZU 2072 Count
    畅通工程 HDU
    Minimum Inversion Number~hdu 1394
    I Hate It HDU
    A Simple Problem with Integers~POJ
    敌兵布阵
    Coins HDU
  • 原文地址:https://www.cnblogs.com/zhber/p/4093654.html
Copyright © 2011-2022 走看看