Skip to content

Commit

Permalink
2001: multiplicity(x, x) == 1
Browse files Browse the repository at this point in the history
This function seeks the largest m such that p**m divides n.
It should exit quickly with int 1 when p and n are the same.
Test added.
  • Loading branch information
smichr committed Jul 25, 2010
1 parent b1b10ed commit 901ebe2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions sympy/ntheory/factor_.py
Expand Up @@ -47,6 +47,8 @@ def multiplicity(p, n):
"""

if p == n:
return 1
if p == 2:
return trailing(n)

Expand Down
2 changes: 2 additions & 0 deletions sympy/ntheory/tests/test_ntheory.py
Expand Up @@ -31,6 +31,8 @@ def test_multiplicity():
assert multiplicity(b, (b**i) * 1000249) == i
# Should be fast
assert multiplicity(10, 10**10023) == 10023
# Should exit quick
assert multiplicity(1, 1) == 1

def test_perfect_power():
assert perfect_power(0) == None
Expand Down

0 comments on commit 901ebe2

Please sign in to comment.