Problem H: Eat Candy

Problem H: Eat Candy
Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 1336  Solved: 646
[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 add k candies into the box. How many candies there are in the box after 109+7 seconds?
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 5
2 3
Sample Output
9
5
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.


来源: http://acm.hzau.edu.cn/problem.php?cid=1009&pid=7
///很容易发现200(可能更小)次后就固定了
#include <iostream>
#include <cstdio>
#include <map>
#include <string>
#include <algorithm>
#include <stdlib.h>
#include <cstring>
using namespace std;
int P[1000];
long long  Handle(long long n,long long k)
{
    long long C = n;
    for(int i=1;i<=200;i++) C = C/2 + k;
    return C;
}
int main()
{
    //freopen("D:\\test.txt","r",stdin);
    //freopen("D:\\tzzt.out","w",stdout);
    long long n,k;
    while(~scanf("%lld %lld",&n,&k)) printf("%lld\n",Handle(n,k));
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值