Class: Integer
- Inherits:
-
Object
- Object
- Integer
- Defined in:
- lib/mathematics.rb
Instance Method Summary collapse
Instance Method Details
#mod_pow(exp, mod) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/mathematics.rb', line 4 def mod_pow(exp, mod) result = 1 base = self while exp > 0 if (exp & 1) == 1 result = (result * base) % mod end exp = exp >> 1 base = (base * base) % mod end result end |