用於模運算的 Python 程式


給定三個數 x、y 和 z,我們的任務是計算 (x^y) % z

示例

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

說明 : 2^3 % 3= 8 % 3 = 2.

演算法

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

示例程式碼

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) 

輸出

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

更新於: 30-7 月-2019

654 次瀏覽

開啟您的職業生涯

完成課程即可獲得認證

開始
廣告
© . All rights reserved.