Best Approximations

Problem 192

Let be a real number.
A best approximation to
for the denominator bound is a rational number in reduced form, with , such that any rational number which is closer to than has a denominator larger than :
For example, the best approximation to for the denominator bound 20 is and the best approximation to for the denominator bound 30 is .
Find the sum of all denominators of the best approximations to for the denominator bound , where is not a perfect square and .