MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / liouville_lambda

Function liouville_lambda

maths/liouville_lambda.py:14–40  ·  view source on GitHub ↗

This functions takes an integer number as input. returns 1 if n has even number of prime factors and -1 otherwise. >>> liouville_lambda(10) 1 >>> liouville_lambda(11) -1 >>> liouville_lambda(0) Traceback (most recent call last): ... ValueError: Input must

(number: int)

Source from the content-addressed store, hash-verified

12
13
14def liouville_lambda(number: int) -> int:
15 """
16 This functions takes an integer number as input.
17 returns 1 if n has even number of prime factors and -1 otherwise.
18 >>> liouville_lambda(10)
19 1
20 >>> liouville_lambda(11)
21 -1
22 >>> liouville_lambda(0)
23 Traceback (most recent call last):
24 ...
25 ValueError: Input must be a positive integer
26 >>> liouville_lambda(-1)
27 Traceback (most recent call last):
28 ...
29 ValueError: Input must be a positive integer
30 >>> liouville_lambda(11.0)
31 Traceback (most recent call last):
32 ...
33 TypeError: Input value of [number=11.0] must be an integer
34 """
35 if not isinstance(number, int):
36 msg = f"Input value of [number={number}] must be an integer"
37 raise TypeError(msg)
38 if number < 1:
39 raise ValueError("Input must be a positive integer")
40 return -1 if len(prime_factors(number)) % 2 else 1
41
42
43if __name__ == "__main__":

Callers

nothing calls this directly

Calls 1

prime_factorsFunction · 0.90

Tested by

no test coverage detected