Computer >> Máy Tính >  >> Lập trình >> Python

Chương trình Python cho phép tính lũy thừa mô-đun

Cho ba số x, y và z, nhiệm vụ của chúng ta là tính (x ^ y)% z

Ví dụ

Input:  x = 2, y = 3, p = 3
Output: 2

Giải thích :2 ^ 3% 3 =8% 3 =2.

Thuật toán

Step 1: Input three numbers.
Step 2: then we use pow() to calculating power and % for modular.
Step 3: display result.

Mã mẫu

x = int(input("Enter First Value ::>"))
y = int(input("Enter Second Value ::>"))
z= (int)(1e9+7) 
# pow function use
d = pow(x, y) % z 
print ("Value Is=",d) 

Đầu ra

Enter First Value ::> 2
Enter Second Value ::> 3
Value Is= 8