คำนวณ (x^y) % z โดยใช้ฟังก์ชัน pow(x, y, mod) ที่มี built-in รองรับ modular exponentiation ได้ตรง
ตัวอย่าง
x=2, y=3, z=3 -> 2^3 % 3 = 8 % 3 = 2
โค้ดตัวอย่าง
x = int(input("Enter First Value: "))
y = int(input("Enter Second Value: "))
z = 10**9 + 7 # common modulus
result = pow(x, y, z)
print("Value Is:", result)
ผลลัพธ์
Enter First Value: 2 Enter Second Value: 3 Value Is: 8