1. 

/**
* Angewandte Mathematik, SS09, IFB 2C
* ACM Problem #10346 (Peter's Smoke)
*
* @author David Leib
* @author Julius Tschannerl
* @version 1.0, 04/22/2009
*
* Status : Accepted
* Runtime: 0.160
*/




import java.util.*;

public class Main {

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);

int k;
int n;
int count;
int butts;
while(sc.hasNext()){
n = sc.nextInt();
k = sc.nextInt();
butts = 0;
count = n;
while(n>=k){
butts = 0;
butts += n%k;
n/=k;
count +=n;
n += butts;
}
System.out.println(count+"");
}

}
}

2.

/**
* Angewandte Mathematik, SS09, IFB 2C
* ACM Problem #10346 (Peter's Smoke)
* Link: http://icpcres.ecs.baylor.edu/onlinejudge/index.php?option=com_onlinejudge&Itemid=8&category=15&page=show_problem&problem=1287
*
* @author Lermer Florian, Taskin Umut, Sayli Hidir
* @version 1.0
*
* Status : Accepted
* Runtime: 0.130
*/

import java.util.Scanner;

public class Main {

public static void main(String[] args) throws ArithmeticException
{
Scanner sc=new Scanner(System.in);
while(sc.hasNext())
{
int n, k, sum = 0, butt = 0;
n=sc.nextInt();
k=sc.nextInt();
while(n > 0)
{
sum += n;
butt += n;
n = butt / k;
butt %= k;
}
System.out.println(sum);
}


}
}