1.

/**
* FWP, Ausgewählte Probleme aus dem ACM Programming Contest, SS10
* Problem: 10346 Peter's Smokes
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=15&page=show_problem&problem=1287
*
* @author Anton Pavlushko, IBB7B,
* @version 1.0, 28/11/2010
*
* Status : Accepted
* Runtime: 0.120
*/

import java.io.*;
import java.text.*;
import java.util.*;
public class Main {

public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String current_line, empty = "";
int number, border, i, j, length, number_local;
int primes [];
Iterator iter;
NumberFormat f;
Formatter f1, f2, f3;
StringTokenizer input_string;
int count,n,k;
String line_1, line_2;

try {
while((current_line=in.readLine())!= null) {
input_string = new StringTokenizer(current_line);
n=Integer.parseInt(input_string.nextToken());
k=Integer.parseInt(input_string.nextToken());

count=n;
while (n/k>0) {
count+=n/k;
n=n/k+n%k;
};

System.out.println(count);
}

} // end try
catch (IOException ee) {
System.err.println("Error: " + ee);
}
}
}


2.

/**
* FWP, Ausgewählte Probleme aus dem ACM Programming Contest, SS10
* Problem: 10346 Peter's Smokes
*
* @author Robert Reichart
*
* Status : Accepted
* Runtime: 0.144
*/

import java.util.*;
class Main{
public static void main(String... args){
Scanner in = new Scanner(System.in);
while (in.hasNextInt())
{
int n = in.nextInt();
int k = in.nextInt();
int total_cigar=0;
int butt=0;
while (n > 0) {
total_cigar += n; /* accumulate all new cigars so far */
butt += n; /* after Peter smokes these n cigar, we have n butts */
n = butt / k; /* so these n butts become new cigars */
butt %= k; /* butts left are reserved for future cigars */
}
System.out.println(total_cigar);
}
}
}