Poj Solution 2509

http://poj.org/problem?id=2509

//* @author ������<hongxp11@163.com>
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);
    }
  }
}

											
This entry was posted in poj. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *