E - 其实这也是一道基础送分题

After passing a test, Vasya got himself a box of nn candies. He decided to eat an equal amount of candies each morning until there are no more candies. However, Petya also noticed the box and decided to get some candies for himself.

This means the process of eating candies is the following: in the beginning Vasya chooses a single integer kk, same for all days. After that, in the morning he eats kkcandies from the box (if there are less than kk candies in the box, he eats them all), then in the evening Petya eats 10%10% of the candies remaining in the box. If there are still candies left in the box, the process repeats — next day Vasya eats kkcandies again, and Petya — 10%10% of the candies left in a box, and so on.

If the amount of candies in the box is not divisible by 1010, Petya rounds the amount he takes from the box down. For example, if there were 9797 candies in the box, Petya would eat only 99 of them. In particular, if there are less than 1010 candies in a box, Petya won't eat any at all.

Your task is to find out the minimal amount of kk that can be chosen by Vasya so that he would eat at least half of the nn candies he initially got. Note that the number kkmust be integer.

Input

The first line contains a single integer nn (1≤n≤10181≤n≤1018) — the initial amount of candies in the box.

Output

Output a single integer — the minimal amount of kk that would allow Vasya to eat at least half of candies he got.

Example

Input

68

Output

3

Note

In the sample, the amount of candies, with k=3k=3, would change in the following way (Vasya eats first):

68→65→59→56→51→48→44→41→37→34→31→28→26→23→21→18→17→14→13→10→9→6→6→3→3→068→65→59→56→51→48→44→41→37→34→31→28→26→23→21→18→17→14→13→10→9→6→6→3→3→0.

In total, Vasya would eat 3939 candies, while Petya —29


题意:两个人吃糖,A每天吃k颗糖,B每天吃剩余糖的10%向下取整。A每天先吃,B后吃。问k至少为多少,能保证A总共吃的糖大于总量的一半。

思路:2分k+模拟检验k是否满足。

代码:.

#include

using namespace std;

typedef long long ll;

ll n;

int check(ll x){

    ll tmp = n, tot = 0;

    while (tmp){

        if (tmp > x){

            tot += x;

            tmp -= x;

            tmp -= tmp/10;

        } else {

            tot += tmp;

            tmp = 0;

        }

    }

    if (tot >= n/2+(n%2))

        return 1;

    return 0;

}

int main()

{

    scanf("%I64d",&n);

    ll l = 1, r = n, mid;

    ll ans = n;

    while (r >= l){

        mid = (r+l)/2;

        int flag = check(mid);

        if (flag){

            r = mid-1;

            ans = min(ans,mid);

        } else {

            l = mid + 1;

        }

    }

    cout<

    return 0;

}

---------------------

作者:PiscesCrab

来源:CSDN

原文:https://blog.csdn.net/PiscesCrab/article/details/80872398

版权声明:本文为博主原创文章,转载请附上博文链接!

你可能感兴趣的:(E - 其实这也是一道基础送分题)