Last active
July 15, 2021 04:58
-
-
Save betaprojects/160e48ff019bc0974e41c40ebb519699 to your computer and use it in GitHub Desktop.
Project Euler & HackerRank problem 97 solution: Calculate the last 12-digits of large number in the form A x B^C + D such as the non-Mersenne prime 28433 × 2^7830457+1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
s = 0 | |
m = 10**12 | |
for _ in range(int(input())): | |
a, b, c, d = map(int, input().split()) | |
s+= (a * pow(b, c, m) + d) % m | |
print(f'{s % m : 012d}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment