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);
    }
  • 相关阅读:
    python kivy 简单入门
    django 入门实例
    window docker安装
    apache进程和用户请求的关系
    php cookie工作原理
    react-router 简单的nginx配置
    node单线程支撑高并发原理(node异步I/O)
    知识图谱
    java
    java
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4908638.html
Copyright © 2011-2022 走看看