zoukankan      html  css  js  c++  java
  • 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 + .. + ( - 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
     
    Note

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

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

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

    题解:奇偶关系

    ///1085422276
    #include<bits/stdc++.h>
    using namespace std ;
    typedef long long ll;
    #define mem(a) memset(a,0,sizeof(a))
    #define pb push_back
    #define meminf(a) memset(a,127,sizeof(a));
    
    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;
    }
    //****************************************
    #define maxn 1000+5
    #define mod 1000000007
    
    
    int main(){
    
    
        ll n=read();
        if(n%2==0){
            cout<<n/2<<endl;
        }
        else {
            cout<<(n-1)/2-n<<endl;
        }
      return 0;
    }
    代码
  • 相关阅读:
    markdown语法
    GIT基本操作
    函数rest参数和扩展
    axios基础介绍
    Vue-Resource的使用
    Vue-router的介绍
    Vue2.0+组件库总结
    Vue 项目de一些准备工作
    VUE.js入门学习(5)- 插槽和作用域插槽
    VUE.js入门学习(4)-动画特效
  • 原文地址:https://www.cnblogs.com/zxhl/p/4948729.html
Copyright © 2011-2022 走看看