-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.java
More file actions
38 lines (35 loc) · 1.16 KB
/
Copy pathSolution.java
File metadata and controls
38 lines (35 loc) · 1.16 KB
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
package java_loops;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.Scanner;
public class Solution {
public static void main(String[] args) throws FileNotFoundException {
Scanner in = new Scanner(new FileReader("./data/java_loops/input"));
int t = in.nextInt();
StringBuilder stringBuilder = new StringBuilder();
for(int i = 0; i < t; i++) {
int a = in.nextInt();
int b = in.nextInt();
int n = in.nextInt();
System.out.println("n:" +n);
int prev = 0;
int prevLoop = 1;
for(int loop = 1; loop <= n; loop ++) {
prevLoop = prevLoop * 2;
int newAmt = prevLoop * b;
int calc = 0;
if(loop == 1) {
calc = a + b;
prevLoop = 1;
} else {
calc = prev + newAmt;
}
prev = calc;
stringBuilder.append(calc).append(" ");
}
stringBuilder.append("\n");
}
System.out.println(stringBuilder);
in.close();
}
}