Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

快速幂取模算法 | 一瓜算法小册 #12

Open
Desgard opened this issue Feb 18, 2020 · 1 comment
Open

快速幂取模算法 | 一瓜算法小册 #12

Desgard opened this issue Feb 18, 2020 · 1 comment

Comments

@Desgard
Copy link
Owner

Desgard commented Feb 18, 2020

https://www.desgard.com/algo/docs/part2/ch01/2-quick-pow-mod/

快速幂取模算法

@wuxiangjinxing
Copy link

wuxiangjinxing commented Mar 14, 2022

以下代码TLE了,能否请帮忙指点一下应该如何优化?非常感谢。
很抱歉我实在搞不懂如何在这里正确显示缩进,用``的话整个代码都会缩成一行。如果看不清楚的话可以看这里:
https://docs.google.com/document/d/1N3HKnXOCodzWyg8hag9kRriD6k_kGsFIEf7hD6HNi9k/

def superPow(self, a: int, b: List[int]) -> int:
    res = 1
    ind = 1
    for i in range(len(b) - 1, -1, -1):
        v = b[i] * ind
        x = a
        while v > 0:
            if v & 1:
                res *= x
                res %= 1337
            x *= x
            x %= 1337
            v >>= 1          
        ind *= 10
    return res % 1337

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants