-
Notifications
You must be signed in to change notification settings - Fork 111
/
solution.java
45 lines (36 loc) · 1.23 KB
/
solution.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
import java.io.*;
import java.util.*;
public class solution {
public static void main(String[] args) {
/*
* Enter your code here. Read input from STDIN. Print output to STDOUT. Your
* class should be named Solution.
*/
Scanner input = new Scanner(System.in);
int T = input.nextInt();
for (int i = 0; i < T; i++) {
int n = input.nextInt() - 1;// Minus 1 to account for 0 starting stone
int a = input.nextInt();
int b = input.nextInt();
// Edge case where no iterations are required
if (a == b) {
System.out.println(a * n + " ");
continue;
}
// make sure a is our min
if (a > b) {
int temp = a;
a = b;
b = temp;
}
int min = a * n;
int max = b * n;
// We only need to increment by difference because there are only two stones to
// choose from each time
for (int finalSteps = min; finalSteps <= max; finalSteps += (b - a)) {
System.out.print(finalSteps + " ");
}
System.out.println();
}
}
}