-
Notifications
You must be signed in to change notification settings - Fork 692
/
Solution.java
45 lines (36 loc) · 1.38 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
//Problem:
//Java 8
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
int tmp = a;
a = Math.min(a,b);
//If b was the min then set it to old value of a
b = (a == b) ? tmp : b;
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();
}
}
}