Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local bigint = require("../bigint")
- local mod = 1247946709
- local a = 24
- local function modPow(b, e, m)
- if m == 1 then
- return 0
- else
- b = bigint.new(b)
- e = bigint.new(e)
- m = bigint.new(m)
- local z = bigint.new(0)
- local u = bigint.new(1)
- local d = bigint.new(2)
- local r = bigint.new(1)
- b = b % m
- print(bigint.unserialize(e / bigint.new(2), "s"))
- while bigint.compare(e, z, ">") do
- if bigint.compare(e % d, u, "==") then
- r = (r * b) % m
- end
- e = e / d
- b = (b ^ d) % m
- end
- return bigint.unserialize(r, "s")
- end
- end
- print(modPow(a, 1000, mod))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement