首页 > 专题系列 > Java解POJ > POJ 2509 Peter’s smokes [解题报告] Java
2013
11-11

POJ 2509 Peter’s smokes [解题报告] Java

Peter’s smokes

问题描述 :

Peter has n cigarettes. He smokes them one by one keeping all the butts. Out of k > 1 butts he can roll a new cigarette.

How many cigarettes can Peter have?

输入:

Input is a sequence of lines. Each line contains two integer numbers giving the values of n and k.

输出:

For each line of input, output one integer number on a separate line giving the maximum number of cigarettes that Peter can have.

样例输入:

4 3
10 3
100 5

样例输出:

5
14
124

解题代码:

//* @author 洪晓鹏<[email protected]>
import java.util.Scanner;


public class Main {
	public static void main(String[] args)
	{
	Scanner in = new Scanner(System.in);
	while(in.hasNext())
	{
		int n = in.nextInt();
		int k = in.nextInt();
		int temp = n;
		int add = 0;
		while(n>=k)
		{
			
			int diff = n/k;
			add = add + diff;
			n = diff  + n - (n/k)*k;
	
		}
		System.out.println(temp+add);
	}
  }
}

  1. Good task for the group. Hold it up for every yeara??s winner. This is a excellent oppotunity for a lot more enhancement. Indeed, obtaining far better and much better is constantly the crucial. Just like my pal suggests on the truth about ab muscles, he just keeps obtaining much better.