题解 | #【模板】快速幂Ⅰ ‖ 整数#

【模板】快速幂Ⅰ ‖ 整数

https://www.nowcoder.com/practice/3d624107a6904da1bd0e8c9c85e17167

t = int(input())
def qpow(x,y,mod):
    res = 1
    while y:
        if y & 1:
            res *= x
            res %= mod
        x *= x
        x %= mod
        y >>= 1
    return res % mod

for _ in range(t):
    x,y,p = map(int,input().split())
    print(qpow(x,y,p))

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务