For Christmas, Santa gifts us a special machine. This special machine takes as input any relatively prime positive integers $a$, $n$ and returns the order of $a$ modulo$ n$ as the output, that is to say : returns the least positive integer $b$ such that $a^b \equiv 1$ mod $n$. Using this special machine, devise an algorithm of time complexity at most $O(\log (n))$ to factorize natural numbers $n$ of the form $pq$, where $p$, $q$ are safe primes (which means $p$, $q$, $\frac{p-1}{2}$ , $\frac{q-1}{2}$ are all primes greater than $5$). Note : You should assume that calling the special machine is $O(1)$, and for two positve integers $a$ and $b$, calculating gcd$(a, b)$ is $O(\log (\ max (a, b))$.
Problem
Source: 2021 IGMO Christmas Edition R2 #6 https://artofproblemsolving.com/community/c3685419_igmo
Tags: algorithm, prime factorization, number theory