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. linux下使用mutt发送带附件的邮件

    echo "hello"|mutt -s "world" -a hack.jpg -- name@address.com

  2. Docker的简单认知

    Docker images: docker image是一个只读打模板,用来创建Docker 容器 Docker Registers 互联网上存储images的地方 Docker containers ...

  3. wcf wpf

    转 http://blog.csdn.net/thunder09/article/details/5792157 WPF就是所谓下一代Windows界面层技术,我觉得还有满有前途的.不过Vista发布 ...

  4. 华为oj 计算字符个数

    练手而已 #include <stdio.h> #include <string.h> int main(void) { char string[200]={'\0'}; in ...

  5. VC进程提权

    如果我们想读取目标进程中的内存 就需要将进程提权 否则访问失败. 下面是提权代码 #include <TlHelp32.h> /****************************** ...

  6. 16 Socket通信(简单例子)

      服务端代码: import java.io.*; import java.net.ServerSocket; import java.net.Socket; import java.util.Da ...

  7. MyEclipse java was started but returned exit code=-1

    java was started but returned exit code=-1 Vm指的是java虚拟机,默认你安装MyEclipse时会自带一个java虚拟机,Vm配置那一行换成你安装的jav ...

  8. Symfony2 Doctrine从现有Database生成Entity(转载自http://blog.it985.com/6809.html)

    在我的以前一章Symfony之十分钟入门说了怎样生成数据库,然后设计实体Entity,再同步数据库的表结构,一般我们的顺序都是这样:生成数据库->设计实体Entity->同步数据库表结构. ...

  9. Sherlock and GCD

    1 import fractions, functools, sys if __name__ == '__main__': T = int(sys.stdin.readline()) for _ in ...

  10. python安装——Windows平台

    刚刚申请博客,第一次写随笔,记录下自己最近的学习情况,希望自己能够不断的学习,不断的丰富自己~ 最近刚开始学python,记录一下,希望大家相互学习,批评指正~ 1.下载python:https:// ...