Modular Exponentiation 2 by 51b

-module m.
-export[m/0].
m()->case io:fread('',"~d~d~d")of{ok,A}->io:write(f(A)),io:nl(),m();_->0end.
f([_,0,_])->1;f([A,B,C])->if B rem 2>0->A;0<1->1end*f([A*A rem C,B div 2,C])rem C.

Note that non-ascii characters in the above source code will be escaped (such as \x9f).

download

return to the top page