CF991C Candies

原题链接:http://codeforces.com/contest/991/problem/C

Candies

After passing a test, Vasya got himself a box of n n 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 k, same for all days. After that, in the morning he eats k k candies from the box (if there are less than k 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 k k candies again, and Petya — 10% of the candies left in a box, and so on.

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

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

Input

The first line contains a single integer n (1n1018) ( 1 ≤ n ≤ 10 18 ) — the initial amount of candies in the box.

Output

Output a single integer — the minimal amount of k k 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=3, would change in the following way (Vasya eats first):

6865595651484441373431282623211817141310966330 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 → 0 .

In total, Vasya would eat 39 39 candies, while Petya — 29 29 .

题解

因为每次糖果都会缩水 10% 10 % 1018 10 18 只要 300 300 多次就没了,那么就愉快的二分答案吧,复杂度 O(log2n×log1091018) O ( l o g 2 n × l o g 10 9 10 18 )

代码
#include<bits/stdc++.h>
using namespace std;
long long n,le,ri,mid;
bool check(long long k)
{
    long long less=0,res=n;
    for(;res>0;res-=k,less+=(res>0?res:0)/10,res-=res/10);
    return less<=n/2;
}
void in(){scanf("%I64d",&n);}
void ac()
{
    le=1,ri=n/2+1;
    while(le^ri)mid=le+ri>>1,check(mid)?ri=mid:le=mid+1;
    printf("%I64d",le);
}
int main(){in();ac();}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

ShadyPi

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

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

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

打赏作者

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

抵扣说明:

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

余额充值