Eat Candy

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 8  Solved: 6
[Submit][Status][Web Board]

Description

There is a box with infinite volume. At first there are ncandies 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+7seconds?

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.

题解:每次n为n的一半加k,问经过1e9+7次后的值;
代码:
import java.util.Scanner;

public class EatCandy {
public static void main(String[] args){
int n, k;
Scanner cin = new Scanner(System.in);
while(cin.hasNext()){
n = cin.nextInt();
k = cin.nextInt();
while(n != (n/ + k)){
n = n / + k;
}
System.out.println(n);
}
}
}

Eat Candy(暴力,水)的更多相关文章

  1. [Usaco2008 Feb]Line连线游戏[暴力][水题]

    Description Farmer John最近发明了一个游戏,来考验自命不凡的贝茜.游戏开始的时 候,FJ会给贝茜一块画着N (2 <= N <= 200)个不重合的点的木板,其中第i ...

  2. Codeforces Round #280 (Div. 2) A B C 暴力 水 贪心

    A. Vanya and Cubes time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  3. Codeforces Round #409 (rated, Div. 2, based on VK Cup 2017 Round 2) A B C D 暴力 水 二分 几何

    A. Vicious Keyboard time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  4. BZOJ4292 PA2015 Równanie 【暴力水题】

    BZOJ4292 PA2015 Równanie Description 对于一个正整数n,定义f(n)为它十进制下每一位数字的平方的和.现在给定三个正整数k,a,b,请求出满足a<=n< ...

  5. Codeforces Round #321 (Div. 2)-A. Kefa and First Steps,暴力水过~~

    A. Kefa and First Steps time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  6. hdoj--1716--排列2(暴力水题)

     排列2 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Sub ...

  7. HDU 4691 正解后缀数组(暴力也能过)

    本来是个后缀数组,考察算法的中级题目,暴力居然也可以水过,就看你跳不跳坑了(c++和G++返回结果就很不一样,关键看编译器) 丝毫不差的代码,就看运气如何了.唯一差别c++还是G++,但正解是后缀数组 ...

  8. 转载:字符串hash总结(hash是一门优雅的暴力!)

    转载自:远航休息栈 字符串Hash总结 Hash是什么意思呢?某度翻译告诉我们: hash 英[hæʃ] 美[hæʃ]n. 剁碎的食物; #号; 蔬菜肉丁;vt. 把…弄乱; 切碎; 反复推敲; 搞糟 ...

  9. HDU 2089 不要62 | 暴力(其实是个DP)

    题目: http://acm.hdu.edu.cn/showproblem.php?pid=2089 题解: 暴力水过 #include<cstdio> #include<algor ...

随机推荐

  1. iphone UIScrollView缩放

    allImageScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 768, 1024)]; allImageScrol ...

  2. [2011山东省第二届ACM大学生程序设计竞赛]——Identifiers

    Identifiers Time Limit: 1000MS Memory limit: 65536K 题目:http://acm.sdut.edu.cn/sdutoj/problem.php?act ...

  3. JMeter数据库性能测试

    要测试一个服务器的性能,客户要求向数据库内 1000/s(每插入一千条数据)的处理能力 前提条件:一个数据库:test   数据库下面有一张表:user   表中有两个字段:username.pass ...

  4. [Redux] Extracting Container Components -- Complete

    Clean TodoApp Component, it doesn't need to receive any props from the top level component: const To ...

  5. Web API零碎知识

    查看EF生成的sql的方法 1.通过在context中设置可以追踪EF[版本必须是6.0或以上]中生成的sql public BookServiceContext() : base("nam ...

  6. Qt串口通信

    1. Qt串口通信类QSerialPort 在Qt5的的更新中,新增了串口通信的相关接口类QSerialPort,这使得在开发者在使用Qt进行UI开发时,可以更加简单有效地实现串口通信的相关功能. 开 ...

  7. 0130——UIScrollView

    1.contentSize幕布实际大小决定滚动的方向,如果小于图片本身不滚动,默认也是不滚动 view.contentSize = CGSizeMake(1280, 200); 而frame只是用来显 ...

  8. iOS之断点下载,使用NSURLSession简单封装

    最近公司需要做个文件管理的功能模块,刚交到博主手上时,头都大了.因为没做过这方面的东西,只好咬牙加班,并请教某位大神,指点了一下,清楚研究方向,找了网上大量资料,最后实现简单的封装. 上代码:.h文件 ...

  9. 决策树简单介绍(二) Accord.Net中决策树的实现和使用

    决策树介绍 决策树是一类机器学习算法,可以实现对数据集的分类.预测等.具体请阅读我另一篇博客(http://www.cnblogs.com/twocold/p/5424517.html). Accor ...

  10. mysql索引之组合索引

    多列索引又称组合索引,在mysql的查询操作中,我们经常会遇到多个搜索条件,如:$sql = "select * from article where content='ma4' and t ...