A - MaratonIME stacks popcorn buckets

简介: A - MaratonIME stacks popcorn buckets

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

题目大意:给你一个数n,让你求1~n的和减去n-1;

思路:这个题T了好几次。。一直都是直接用暴力来做,总是T,最后换成了等差数列AC了。

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
   long long int sum, n;
   scanf("%lld", &n);
   sum = (n * (n - 1)) / 2 + 1;
   printf("%lld\n", sum);
    return 0;
}


相关文章
|
10月前
|
存储 算法 Java
JEP 331: Low-Overhead Heap Profiling
JEP 331: Low-Overhead Heap Profiling
78 1
|
存储
LeetCode 232. Implement Queue using Stacks
使用栈实现队列的下列操作: push(x) -- 将一个元素放入队列的尾部。 pop() -- 从队列首部移除元素。 peek() -- 返回队列首部的元素。 empty() -- 返回队列是否为空。
64 0
LeetCode 232. Implement Queue using Stacks
Data Structures (三) - 栈Stack实现
Data Structures (三) - 栈Stack实现
Data Structures (三) - 栈Stack实现
Data Structures and Algorithms (English) - 6-2 Two Stacks In One Array(20 分)
Data Structures and Algorithms (English) - 6-2 Two Stacks In One Array(20 分)
126 0
|
SQL 分布式计算 负载均衡
Out of memory due to hash maps used in map-side aggregation解决办法
在运行一个group by的sql时,抛出以下错误信息: Task with the most failures(4):  -----Task ID:  task_201411191723_723592_m_000004URL:  http://DDS0204.
1228 1
1094. The Largest Generation (25)
#include #include using namespace std; vector v[100]; int maxdepth = 0, level[100] = {0}; bool visited[100] = ...
724 0
|
BI 机器学习/深度学习 人工智能
1098. Insertion or Heap Sort (25) 21'
#include #include #include using namespace std; vector a, b; //note:堆排序从1开始 void downAdjust(int low, int high...
1127 0
|
Java 索引 iOS开发
OutOfMemoryError系列(7): Requested array size exceeds VM limit
这是本系列的第七篇文章, 相关文章列表: OutOfMemoryError系列(1): Java heap space OutOfMemoryError系列(2): GC overhead limit exceeded OutOfMemoryError系列(3): Perm...
2923 0