Created
September 11, 2021 07:33
-
-
Save kadaliao/6cb92042c752520b5f52ae1a22fef366 to your computer and use it in GitHub Desktop.
快速幂方法
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import hypothesis.strategies as st | |
from hypothesis import given | |
def quick_pow(a: int, b: int) -> int: | |
base, ans = a, 1 | |
while b: | |
if b & 1: | |
ans *= base | |
base *= base | |
b >>= 1 | |
return ans | |
@given(st.integers(min_value=1, max_value=100), st.integers(min_value=0, max_value=20)) | |
def test_quick_pow(a, b): | |
print(a, b) | |
assert pow(a, b) == quick_pow(a, b) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment