PE其他解題報告請參考這裏,本題答案在留言首條
Large non-Mersenne prime
Problem 97
The first known prime found to exceed one million digits was discovered in 1999, and is a Mersenne prime of the form ; it contains exactly 2,098,960 digits. Subsequently other Mersenne primes, of the form 2p−1, have been found which contain more digits.
However, in 2004 there was found a massive non-Mersenne prime which contains 2,357,207 digits:
Find the last ten digits of this prime number.
題意:
讓你求的最後十位
分析:
快速冪直接搞定
參考代碼
mod = int(1e10)
def quick_pow(a, b):
res = 1
while (b):
if (b & 1): res = res * a % mod
a *= a
b >>= 1
return res
print((28433 * quick_pow(2, 7830457) + 1)%mod)
閱讀好習慣:點贊 + 收藏~