A-M baby
This commit is contained in:
parent
764da6cbbb
commit
db842d013d
19005 changed files with 197040 additions and 7 deletions
|
|
@ -0,0 +1,6 @@
|
|||
require 'openssl'
|
||||
|
||||
a = 2988348162058574136915891421498819466320163312926952423791023078876139
|
||||
b = 2351399303373464486466122544523690094744975233415544072992656881240319
|
||||
m = 10 ** 40
|
||||
puts a.to_bn.mod_exp(b, m)
|
||||
18
Task/Modular-exponentiation/Ruby/modular-exponentiation-2.rb
Normal file
18
Task/Modular-exponentiation/Ruby/modular-exponentiation-2.rb
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
class Integer
|
||||
def rosetta_mod_exp(exp, mod)
|
||||
exp < 0 and raise ArgumentError, "negative exponent"
|
||||
prod = 1
|
||||
base = self % mod
|
||||
until exp.zero?
|
||||
exp.odd? and prod = (prod * base) % mod
|
||||
exp >>= 1
|
||||
base = (base * base) % mod
|
||||
end
|
||||
prod
|
||||
end
|
||||
end
|
||||
|
||||
a = 2988348162058574136915891421498819466320163312926952423791023078876139
|
||||
b = 2351399303373464486466122544523690094744975233415544072992656881240319
|
||||
m = 10 ** 40
|
||||
puts a.rosetta_mod_exp(b, m)
|
||||
Loading…
Add table
Add a link
Reference in a new issue