chakravala ( n x p q m -- n x' p' q' m' )


Vocabulary
project-euler.066

Inputs
nan object
xan object
pan object
qan object
man object


Outputs
nan object
x'an object
p'an object
q'an object
m'an object


Definition


:: chakravala ( n x p q m -- n x' p' q' m' )
n sqrt ceiling >integer :> upper-bound upper-bound m abs -
:> lower-bound x neg m abs rem
:> reminder lower-bound reminder -
:> distance reminder distance m abs / ceiling 0 max m abs *
+ :> x' n x' p x' * n q * + m abs / p x' q * + m abs /
x' sq n - m / ;