Skip to content

Instantly share code, notes, and snippets.

@betaprojects
Last active July 15, 2021 04:58
Show Gist options
  • Save betaprojects/160e48ff019bc0974e41c40ebb519699 to your computer and use it in GitHub Desktop.
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
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