{"record":{"id":"1161e2cbe8395b49","repo":"TheAlgorithms/Java","slug":"number-must-be-greater-than-zero","errorCode":null,"errorMessage":"Number must be greater than zero.","messagePattern":"Number must be greater than zero\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/thealgorithms/maths/Prime/LiouvilleLambdaFunction.java","lineNumber":30,"sourceCode":" *\n * */\n\npublic final class LiouvilleLambdaFunction {\n    private LiouvilleLambdaFunction() {\n    }\n\n    /**\n     * This method returns λ(n) of given number n\n     *\n     * @param number Integer value which λ(n) is to be calculated\n     * @return  1 when number has even number of prime factors\n     *         -1 when number has odd number of prime factors\n     * @throws IllegalArgumentException when number is negative\n     */\n    public static int liouvilleLambda(int number) {\n        if (number <= 0) {\n            // throw exception when number is less than or is zero\n            throw new IllegalArgumentException(\"Number must be greater than zero.\");\n        }\n\n        // return 1 if size of prime factor list is even, -1 otherwise\n        return PrimeFactorization.pfactors(number).size() % 2 == 0 ? 1 : -1;\n    }\n}\n","sourceCodeStart":12,"sourceCodeEnd":37,"githubUrl":"https://github.com/TheAlgorithms/Java/blob/fdfb9a395b310167a66bd29e311e36e0e3e9b964/src/main/java/com/thealgorithms/maths/Prime/LiouvilleLambdaFunction.java#L12-L37","documentation":"Thrown by LiouvilleLambdaFunction.liouvilleLambda(int number) when number <= 0. The Liouville function λ(n) is defined only for positive integers (it counts the parity of prime factors with multiplicity), so zero and negatives are out of domain. The guard fires before delegating to PrimeFactorization.pfactors.","triggerScenarios":"Calling liouvilleLambda(0), liouvilleLambda(-5), or any liouvilleLambda(number) where number <= 0.","commonSituations":"User-supplied integer not validated for positivity; result of an arithmetic expression (subtraction, decrement) that crossed zero; loop index off-by-one hitting 0; deserialized field that accepted non-positive values.","solutions":["Validate number > 0 at the caller and reject or clamp before calling liouvilleLambda.","Fix upstream arithmetic (loop bounds, subtractions) producing non-positive values.","If 0 or negatives are meaningful in your domain, define your own handling before calling."],"exampleFix":"// before\nint lambda = LiouvilleLambdaFunction.liouvilleLambda(n);\n\n// after\nif (n <= 0) {\n    throw new IllegalArgumentException(\"n must be > 0: \" + n);\n}\nint lambda = LiouvilleLambdaFunction.liouvilleLambda(n);","handlingStrategy":"validation","validationCode":"if (number <= 0) {\n    throw new IllegalArgumentException(\"number must be > 0: \" + number);\n}\nint lambda = LiouvilleLambdaFunction.liouvilleLambda(number);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate positive-integer inputs at the boundary before calling number-theory functions.","Audit arithmetic that produces inputs (subtractions, decrements) for non-positive results.","Treat 0 and negatives as domain errors for Liouville/Möbius/square-free functions."],"tags":["math","number-theory","invalid-argument","non-positive"],"backgroundTag":null,"analyzedSha":"fdfb9a395b310167a66bd29e311e36e0e3e9b964","analyzedAt":"2026-08-13T23:36:13.315Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}