-
Notifications
You must be signed in to change notification settings - Fork 0
/
10346.java
56 lines (45 loc) · 1016 Bytes
/
10346.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/**
*
*/
package apr;
import java.util.*;
import java.lang.*;
import java.io.*;
/**
* @author Saif_sust_2013331007
*
*/
public class Main {
/**
* @param args
*/
public static void main(String[] args) throws Exception {
try {
new UVA().new Solver().Solution();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
class UVA {
private int peterSmoke(int n, int k) {
if (n < k)
return 0;
return n / k + peterSmoke(n / k + n % k, k);
}
protected class Solver {
protected void Solution() {
int n, k;
while (scanner.hasNext()) {
n = scanner.nextInt();
k = scanner.nextInt();
System.out.println(peterSmoke(n, k) + n);
}
}
}
// private BufferedReader scanner = new BufferedReader(new
// InputStreamReader(System.in));
// private DataInputStream scanner = new DataInputStream(System.in);
// private Scanner scanner = fileFactory.scanner();
private Scanner scanner = new Scanner(System.in);
}