forked from Juhi-Shelar/Competitive-Coding-Practice
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRecyclingMachine.java
More file actions
53 lines (33 loc) · 737 Bytes
/
RecyclingMachine.java
File metadata and controls
53 lines (33 loc) · 737 Bytes
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
//October Easy 2019 : Problem DigitPlay
import java.util.Scanner;
public class RecyclingMachine {
static long foo(long n, long k) {
long res = 0;
while(n>=k) {
long quo = n/k;
long rem = n%k;
res = res + quo;
n = rem + quo;
}
return res;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
long[] n = new long[t];
long[] k = new long[t];
for(int i=0; i<t; i++) {
n[i] = sc.nextLong();
k[i] = sc.nextLong();
}
for(int i=0; i<t; i++) {
System.out.println(foo(n[i],k[i]));
}
}
}
/*
String s = sc.next();
String temp[] = s.split(" ");
n[i] = Long.parseLong(temp[0]);
k[i] = Long.parseLong(temp[1]);
*/