Problem H: Eat Candy
来源:互联网 发布:windows聚焦 win7 编辑:程序博客网 时间:2024/05/29 08:31
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 integers n,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.
#include<stdio.h>#include<iostream>using namespace std;int main(){ int i,j; int n,k; while(~scanf("%d%d",&n,&k)) { int m; while(1) { n=n/2; n=n+k; if(m==n) break; m=n; } printf("%d\n",n); } return 0;}
0 0
- Problem H: Eat Candy
- Problem H: Eat Candy
- Problem H: Eat Candy
- Problem H: Eat Candy
- hzauoj Problem H: Eat Candy (暴力)
- HZAU 1017 Eat Candy
- HZAU--19--Eat Candy(水题)
- 3991 H. Eat or Study
- eat
- eat
- Problem H
- Problem H
- Problem H
- Problem H
- Problem H
- Problem H
- Problem H
- problem h
- hadoop 新API与旧API对比
- 致我亲爱的你
- 机器学习竞赛技巧
- L2-008. 最长对称子串
- android ListView的简单使用与优化
- Problem H: Eat Candy
- Navigator 对象属性 详细介绍
- Pie or die(欧拉函数,求最大公约数)
- F12调试工具 在任务栏出不来
- Android详细的对话框AlertDialog.Builder使用方法
- Python Cookbook 学习笔记 第一章Data Structures and Algorithms
- 5月项目心得
- 编程学习困惑
- pandas使用