A - MaratonIME stacks popcorn buckets ( Gym - 101375A )

A - MaratonIME stacks popcorn buckets

 Gym - 101375A 

Problem Description

Statements

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

代码如下:

Hint:每次前两个加起来并掉一个,所以最后全部加起来,再减去掉的n-1个。

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
    long long n, sum;
    while(~scanf("%lld", &n))
    {
        sum = (n * (n + 1)) / 2;  // 等差数列前n项和公式, 开始使用for循环,会超时(可能提示WA)
        printf("%lld\n", sum - n + 1);
    }
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

WMYBlog

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值