Python’s integers are arbitrary-precision, meaning you can compute extremely large powers without overflow, unlike fixed-width types in C++[^0^]
Python documentation
Below are two implementations:
Compact One-Liner: Performs the same computation in a single expressive line, ideal for code-golf or succinct contest submissions.
Both approaches correctly handle very large inputs, leveraging Python’s optimized big-integer arithmetic and the optional third argument of pow() for modular reduction[^5^]
Long-Form Script
Read four integers a, b, c, d from input (each on its own line)
a = int(input().strip())
b = int(input().strip())
c = int(input().strip())
d = int(input().strip())
Compute a**b and c**d using Python's built-in exponentiation
result1 = pow(a, b) # equivalent to a ** b
result2 = pow(c, d) # equivalent to c ** d
Print the sum of the two large powers
print(result1 + result2)
Explanation of Steps:
int(input().strip()) parses each line as a Python integer, supporting any size[^0^]
pow(a, b) uses Python’s built-in for exact integer exponentiation in O(log b) time[^3^]
Summing two big integers is also handled natively with arbitrary precision[^0^]
Compact One-Liner
Read input lines and compute (a**b + c**d) in one statement
print(pow(int(input()), int(input())) + pow(int(input()), int(input())))
One-Liner Breakdown:
Each int(input()) reads and converts a line to an integer.
pow(...) computes each power efficiently[^2^]
The + operator adds the two results, and print() outputs the final big integer.
On this page of the site you can watch the video online Big Integer Exponentiation & Modular Power in Python – Long Version + One-Liner with a duration of hours minute second in good quality, which was uploaded by the user CodeVisium 23 April 2025, share the link with friends and acquaintances, this video has already been watched 158 times on youtube and it was liked by 1 viewers. Enjoy your viewing!