The lowest initial numbers in a Fibonacci-like sequence Given a positive integer input N, output the two non-negative numbers, a and b, where a &lt; b, with the lowest possible mean value that will result in the number N being part of the recurring relation sequence:

f(0) = a
f(1) = b
f(n) = f(n-2)+f(n-1)


In case there are more than one solution where the mean of a and b are minimal, then you should output the one with the lowest b.

Your can assume N is within the representative range of integers in your language / system. 

Test cases

N = 1
a = 0, b = 1

N = 15
a = 0, b = 3

N = 21
a = 0, b = 1

N = 27
a = 0, b = 9   &lt;- Tricky test case. [3, 7] is not optimal and [4, 3] is not valid

N = 100
a = 4, b = 10

N = 101
a = 1, b = 12

N = 102
a = 0, b = 3

N = 1000
a = 2, b = 10
APL (Dyalog), 75 71 64 59 53 48 44 43 bytes

2 bytes saved thanks to @Adám

12 bytes saved thanks to @ngn



⊃o/⍨k∊¨+\∘⌽⍣{k≤⊃⍺}¨o←a/⍨&lt;/¨a←,⍉|-\¨⍳2⍴1+k←⎕


Try it online!

Uses ⎕IO←0.

How? This had gone real nuts.

k←⎕ - assign input to k

⍳2⍴1+k←⎕ - Cartesian product of the range 0 to k with itself

|-\¨ - substract each right pair element from the left, and get absolute values

a←,⍉ - transpose, flatten and assign to a

o←a/⍨&lt;/¨a - keep only pairs where the left element is smaller than the right, and assign to o

o now contains list of all pairs with a &lt; b, ordered by their arithematical mean

+\∘⌽⍣{k≤⊃⍺}¨o - for each pair in o, apply fibonacci (reverse the pair and cumsum) until k or higher term is reached

k∊¨ - then decide if k is this last term (meaning it is contained in the sequence)

o/⍨ - and keep pairs in o where the previous check applies

⊃ - return the first result.