Write a function f(a,b,c) that calculates a^b (mod c) in less than 10 seconds.
- a, b < 10^100
- c < 10000.
examples:
f(10^50, 10^50, 54123) = 46555
f(5^99, 10^99, 777) = 1
|
Write a function f(a,b,c) that calculates a^b (mod c) in less than 10 seconds.
examples:
|
|||
dc 1 or 5 charsIn GNU dc, there is the operator
You may assign it to "function" as following:
(also 5 chars...) This assigns |
||||
|
|
Python - 5 chars
Test
|
|||
|
Haskell, 65Takes the liberty of taking the modulus only on set bits of binary
|
|||
|
|
Java 56 charsMy humble attempt with Java.
How to use :
|
|||
|
|
Haskell (54)
This is my algorithm:
|
|||
|
|
|
Python 80 Characters
|
|||
|
|
f=powwould work in Python). – Dogbert Feb 11 '11 at 21:41