# TITLE: Fast Exponentiation, a^b (MOD m) without overflow # AUTHOR: Roy F.A. Maclean # EMAIL: rfamgm at gmail # WEB: http://www.spiderpixel.co.uk/caspro # DATE: 7Jun1998, 6Jun1999, 3Jul2007 # MAKE: CASIO # MODEL: fx6300 or higher # # Enables you to calculate a^b(mod m) without overflow # as long as m<100000 # # e.g. using this program 3^85 == 5(mod 17) # # Whereas if you tried calculating 3^85 directly before # reducing modulo 17 then you would get round-off errors. @@ Program 1 "A"?->A:"B"?->B:"M"?->M A-M*Int (A/M)->A 1->C:Lbl 1 Frac .5B<>0=>CA-M*Int (CA/M)->C Int .5B->B AA-M*Int (AA/M)->A B<>0=>Goto 1 C<0=>M+C->C C