Given integers \$a,b,m, k, n\$ and array \$F = (f_1, f_2,...,f_n)\$ defined as: \begin{cases} f_1 = \text{a}\\ f_2 = \text{b}\\ f_i = (f_{i-1} + f_{i-2}) \text{ mod m},∀i > 2 \end{cases} When \$F\$ array is sorted into a non-decreasing sequence, your task is to find the \$k\$-th integer of the sorted \$F\$ array where \$k ≤ n\$.
Sample I/O
I/O format is flexible.
# I/O format
# a, b, m, k, n -> Output
1, 1, 10, 8, 10 -> 5
8, 2, 15, 7, 63 -> 2
21948, 12412, 42124, 85217, 92412 -> 38508
102492, 128282, 87421, 242122, 341247 -> 61572
42424, 76767, 97487, 3784274, 10421244 -> 35377
50127, 31229, 99887, 9784274, 17421244 -> 56002
11127, 93229, 94823, 20084263, 20421244 -> 93278
Visualization
Let's take the \$1^{st}\$ Sample I/O.
After generating the array \$F\$, our array would be:
\begin{cases}
f_1 = 1\\
f_2 = 1\\
f_3 = 2\\
f_4 = 3\\
f_5 = 5\\
f_6 = 8\\
f_7 = 3\\
f_8 = 1\\
f_9 = 4\\
f_{10} = 5\\
\end{cases}
When sorting the array \$F\$ into a non-decreasing sequence, we will get:
\begin{cases}
f_1 = 1\\
f_2 = 1\\
f_3 = 1\\
f_4 = 2\\
f_5 = 3\\
f_6 = 3\\
f_7 = 4\\
f_8 = 5\\
f_9 = 5\\
f_{10} = 8\\
\end{cases}
Since our given \$k\$ was \$8\$ as per our sample, we will print out the value of \$f_k\$ or \$f_8\$ of the sorted \$F\$ array, the value of which is \$5\$.
Therefore, for our \$1^{st}\$ sample, the output returned was \$5\$.
Winning Criterion
This is a fastest-code
challenge. Timing will be based on the timing shown in the tio.run link provided, in the Debug
section, User Time
. A more precise one with times tested on my machine will be conducted later, since performance on tio.run may vary over time.
The time will be measured by how long it takes to complete all 7 test cases provided in the Sample I/O section.
Standing
Code | Language | Runtime |
---|---|---|
emanresu A | C (gcc) | 0.5 - 3 ms |
emanresu A | Node.js | 1.7 - 4.4 ms |