Linear Sequence
Statement
Goal
Information of linear sequence:A linear sequence is a number pattern that increases or decreases by the same amount each time. (From BBC Bitesize: https://www.bbc.co.uk/bitesize/guides/z7j2pv4/revision/)
You can find the nth term of the sequence by this formula:
nth term = first term of the sequence + (n - 1) * common difference
Task:
You will be given four integers, which have the same difference. For example, (2, 4, 6, 8) is a linear sequence.
You will need to find the formula to find the nth term of the sequence, in the form of (bn+c). The nth term is 1-indexed, i.e. the indexes of the first four terms are 1, 2, 3, 4.
If (bn =0) or (c = 0), do not print that part out.
For example, if the formula is 4n+0, print 4n instead of 4n+0.
If both bn = 0 and c = 0, i.e. the sequence is (0 0 0 0), print 0.
If b = 1 or b = -1, just print n or -n instead of 1n or -1n respectively.
The output formula should be simplified if possible.
For example, each of the following can be simplified:
1n+0 => n
-1n+0 => -n
0n+4 => 4
0n+0 => 0
Input
Line 1: n = 4 integers entered on one line, separated with spaces.
Output
Line 1: Output a formula with the format of bn+c.
Constraints
-100 < each integer in n < 100
b and c are always integers.
b and c are always integers.
Example
Input
4 4 4 4
Output
4
Game modes
Fastest
Test cases
Test 1 Test
Input
4 4 4 4
Output
4
Validator 1 Validator
Input
5 5 5 5
Output
5
Test 2 Test
Input
4 5 6 7
Output
n+3
Validator 2 Validator
Input
11 12 13 14
Output
n+10
Test 3 Test
Input
15 20 25 30
Output
5n+10
Validator 3 Validator
Input
10 19 28 37
Output
9n+1
Test 4 Test
Input
-8 -4 0 4
Output
4n-12
Validator 4 Validator
Input
-9 -5 -1 3
Output
4n-13
Test 5 Test
Input
0 0 0 0
Output
0
Validator 5 Validator
Input
1 1 1 1
Output
1
Test 6 Test
Input
6 5 4 3
Output
-n+7
Validator 6 Validator
Input
-9 -10 -11 -12
Output
-n-8
Test 7 Test
Input
4 8 12 16
Output
4n
Validator 7 Validator
Input
3 6 9 12
Output
3n
Test 8 Test
Input
10 11 12 13
Output
n+9
Validator 8 Validator
Input
3 4 5 6
Output
n+2
Solution language
Solution
Stub generator input