# binsearch width # $9 = min(1e9, 2e18/K/N) $9 = 2000000000000000000 $9 = $9 / K $9 = $9 / N if $9 >= 1000000000 $9 = 1000000000 end $8 = N * N $7 = N * K # $0 = floor( ( sqrt(K^2 + 4) - K ) / 2 ) # = max x [ 0 <= x ] [ x^2 + NKx <= N^2 ] while $9 > 1 # $1 = (next x to test) $1 = $9 / 2 $9 = $9 - $1 $1 = $0 + $1 # test x = $1 # $2 = x^2 + NKx $2 = $1 + $7 $2 = $2 * $1 if $2 <= $8 $0 = $1 end end $0 = $0 + N return $0