Write a method named `getExponent(n,p)` that returns the largest integer exponent `x` such that p^(x) evenly divides `n`. if `p<=1` the method should return `null`/`None` (throw an `ArgumentOutOfRange` exception in C#).

Source: codewars | Difficulty: EASY
Tags: Fundamentals

Mathematics

Starter code: def get_exponent(n, p):
	

Solutions:
def get_exponent(n, p):
	if p > 1:
		x = 0
		while not n % p:
			x += 1
			n //= p
		return x


def get_exponent(n, p, i=0):
	if p <= 1:
		return None
	return get_exponent(n / p, p, i + 1) if n / p == n // p else i


from itertools import count

def get_exponent(n, p):
	if p > 1:
		for res in count():
			(n, r) = divmod(n, p)
			if r:
				return res


def get_exponent(n, p):
	return next(iter((i for i in range(int(abs(n) ** (1 / p)), 0, -1) if n / p ** i % 1 == 0)), 0) if p > 1 else None


def get_exponent(n, p):
	if p <= 1:
		return None
	(x, e) = (0, 1)
	while n % e == 0:
		x += 1
		e *= p
	return x - 1


def get_exponent(n, p):
	i = 1
	if p <= 1:
		return None
	while n % p ** i == 0:
		i += 1
	return i - 1


def get_exponent(n, p):
	if p <= 1:
		return
	return max([i for i in range(1, int(abs(n) ** 0.5)) if n % p ** i == 0], default=0)


def get_exponent(n, p):
	if int(p) <= 1:
		return None
	else:
		x = 1
		while n % p ** x == 0:
			x += 1
	return x - 1


def get_exponent(n, p):
	r = 0
	while n % p ** r == 0 and p > 1:
		r += 1
	if r > 0:
		return r - 1


from math import log

def get_exponent(n, p):
	if p <= 1:
		return None
	(l, i) = (None, 0)
	while p ** i <= abs(n):
		if n % p ** i == 0:
			l = i
		i += 1
	return l