This is due on Wed Apr 9.
You may assume that Euclid's algorithm is polynomial time, and that the repeated squaring algorithm for finding a^b mod n is also polynomial time.
This now gives us a factoring algorithm. We are given n which we know to be composite and are looking for a non-trivial factor. Choose k as large as you can, subject to the constraint that you can use repeated squaring to find a^(k!) mod n for a < n in a reasonable amount of CPU time. Let A= k! as above. Choose random a < n, compute gcd(a, n) and gcd(a^A-1, n). If one of them is a non-trivial factor of n then the algorithm succeeds. If not then repeat with a different a.
(Optional but fun) Use Maple to try out the algorithm I just decsribed with k=1000 and some large random values of n