zoukankan      html  css  js  c++  java
  • Codeforces Round #277 (Div. 2) A. Calculating Function 水题

    A. Calculating Function

    Time Limit: 20 Sec

    Memory Limit: 256 MB

    题目连接

    http://codeforces.com/contest/486/problem/A

    Description

    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 Input

    4

    Sample Output

    2

    HINT

    题意
    f(n) =  - 1 + 2 - 3 + .. + ( - 1)^n

    给你n,然后让你求f(n)

    题解:

    分奇偶啦,奇数就是(n-1)/2-n,偶数就是n/2

    代码

    #include<stdio.h>
    #include<iostream>
    using namespace std;
    int main()
    {
        long long n;scanf("%lld",&n);
        if(n%2==1) printf("%lld
    ",(n-1LL)/2LL - n);
        else printf("%lld
    ",n/2LL);
    }
  • 相关阅读:
    安装开发工具
    CSS基础
    CSS动画
    CSS效果
    CSS布局
    CSS预处理语言
    React开发笔记
    Vue2.0学习笔记
    Vue-cli3.0开发笔记
    项目开发技巧
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4908638.html
Copyright © 2011-2022 走看看