https://123dok.net/document/zx52d6dq-computing-nearest-gcd-with-certification.html