hzauoj Problem H: Eat Candy (暴力)

来源:互联网 发布:迅雷你的网络未连接 编辑:程序博客网 时间:2024/05/22 17:10

Problem H: Eat Candy

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 1333  Solved: 644
[Submit][Status][Web Board]

Description

  There is a box with infinite volume. At first there are n candies in the box. Then every second you will eat some candies, left half of candies (round down) in the box. Then addk candies into the box. How many candies there are in the box after 109+7seconds?

Input

  There are multiple test cases. In each test case, there are only one line contains two integersn,k(1≤n,k≤109+7)

Output

    For each test case, output the answer in one line.

Sample Input

4 52 3

Sample Output

95

HINT



In the first test case:


1st second, 4->2, 2+5 = 7


2nd second, 7->3, 3+5 = 8


3rd second, 8->4, 4+5 = 9


4th second, 9->4, 4+5 = 9



1000000007th           9


So there are 9 candies in the box after 1000000007 seconds.

#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespace std;int main(){long long n,k;while(scanf("%lld%lld",&n,&k)!=EOF){long long pre=n;for(int i=0;i<1e9+7;i++){n=n/2+k;if(pre==n){break;}pre=n;}cout<<n<<endl;}return 0;}


0 0
原创粉丝点击