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.
Nesta página do site você pode assistir ao vídeo on-line Big Integer Exponentiation & Modular Power in Python – Long Version + One-Liner duração hora minuto segundo em boa qualidade , que foi baixado pelo usuário CodeVisium 23 Abril 2025, compartilhe o link com seus amigos e conhecidos, no youtube este vídeo já foi visto 158 vezes e gostou 1 espectadores. Boa visualização!