Efficient way to power and mod in ruby
This is called modular exponentiation and is used heavily in cryptography. Its fairly easy to write a modular exponentiation algorithm, a demonstration is in the wikipedia article listed above.
You can use the standard library openssl to achieve your goal:
require 'openssl'
1_299_709.to_bn.mod_exp(1_300_751, 104_729) # => 90827
Since Ruby 2.5 modular exponentiation is built in:
print 1_299_709.pow(1_300_751, 104_729)