SICP Exercise 1.25
fast-exp inside the expmod procedure gives us the same results but takes much longer.
This happens because good old
expmod keeps squares less than the number whose primality is being checked for.
fast-exp does not do that and keeps squaring the numbers to as high as $$a^m$$.
A better explanation is present at: http://community.lispwiki.org/?sicp-ex-1.25