Skip to content

Instantly share code, notes, and snippets.

@kadaliao
Created September 11, 2021 07:33
Show Gist options
  • Save kadaliao/6cb92042c752520b5f52ae1a22fef366 to your computer and use it in GitHub Desktop.
Save kadaliao/6cb92042c752520b5f52ae1a22fef366 to your computer and use it in GitHub Desktop.
快速幂方法
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