A - MaratonIME stacks popcorn buckets Gym - 101375A

版权声明:本文为博主胡乱瞎写,如有需要,随便转载,顺带给个momo哒。 https://blog.csdn.net/rangran/article/details/81812149

On a Friday afternoon, some members of MaratonIME decided to watch a movie at CinIME.

There were n members who received popcorn buckets numbered from 1 to n.

At a certain moment, bucket 1 had one popcorn, bucket 2 had two popcorns and so on until bucket n, which had n popcorns. As good competitive programmers, they always prefer to simplify things, and decided to gather all the popcorn in just one bucket.

They proceeded on the following way: In bucket 2, they gather the popcorn from buckets 1 and 2. Then, in bucket 3, those of bucket 2 and 3 and so on until the last bucket. Formally, they perform n - 1 movements, on the i-th movement they join the popcorn from buckets i and i + 1 on bucket i + 1. However, they are known to be clumsy and at each moment they join two buckets, they let a single popcorn fall to the ground, which they promptly throw in the trash.

Jiang, the Sharp, realized that maybe the last bucket would be too small to hold all of the popcorn. Therefore, he asked for your help to determine how much popcorn should remain in the last bucket.

Given n, the number of members who decided to watch the movie, print the amount of popcorn that would remain in bucket n. Keep in mind that exactly one popcorn is lost at each step.

Input

The first line contains the integer n (2 ≤ n ≤ 3 * 109) – the number of members from MaratonIME who decided to watch the movie.

Output

An integer: The amount of popcorn the last bucket should have.

Examples

Input

2

Output

2

Input

3

Output

4

Input

1000000

Output

499999500001

每次都丢下一个,原本应该是1,2,3,4,5,6,7,8........,每次都丢下一个1,1,2,3,4,5,6,7,........

利用等差公式求后面n-1的和再加上第一个1;

#include <stdio.h>
#include <stdlib.h>

int main()
{
    long long int n;
    long long int sum=0;
    scanf("%lld",&n);
    if(n==2) sum=2;
    else
        sum=(n-1)*n/2+1;
    printf("%lld",sum);
    return 0;
}

猜你喜欢

转载自blog.csdn.net/rangran/article/details/81812149