{"record":{"id":"4bc1183f908338cb","repo":"TheAlgorithms/C-Sharp","slug":"nameof-n-should-be-more-than-3","errorCode":null,"errorMessage":"{nameof(n)} should be more than 3","messagePattern":"(.+?) should be more than 3","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Algorithms/Numeric/MillerRabinPrimalityChecker.cs","lineNumber":33,"sourceCode":"    ///     </summary>\n    /// <param name=\"n\">Number to check.</param>\n    /// <param name=\"rounds\">Number of rounds, the parameter determines the accuracy of the test, recommended value is Log2(n).</param>\n    /// <param name=\"seed\">Seed for random number generator.</param>\n    /// <returns>True if is a highly likely prime number; False otherwise.</returns>\n    /// <exception cref=\"ArgumentException\">Error: number should be more than 3.</exception>\n    public static bool IsProbablyPrimeNumber(BigInteger n, BigInteger rounds, int? seed = null)\n    {\n        Random rand = seed is null\n            ? new()\n            : new(seed.Value);\n        return IsProbablyPrimeNumber(n, rounds, rand);\n    }\n\n    private static bool IsProbablyPrimeNumber(BigInteger n, BigInteger rounds, Random rand)\n    {\n        if (n <= 3)\n        {\n            throw new ArgumentException($\"{nameof(n)} should be more than 3\");\n        }\n\n        // Input #1: n > 3, an odd integer to be tested for primality\n        // Input #2: k, the number of rounds of testing to perform, recommended k = Log2(n)\n        // Output:   false = “composite”\n        //           true  = “probably prime”\n\n        // write n as 2r·d + 1 with d odd(by factoring out powers of 2 from n − 1)\n        BigInteger r = 0;\n        BigInteger d = n - 1;\n        while (d % 2 == 0)\n        {\n            r++;\n            d /= 2;\n        }\n\n        // as there is no native random function for BigInteger we suppose a random int number is sufficient\n        int nMaxValue = (n > int.MaxValue) ? int.MaxValue : (int)n;","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/TheAlgorithms/C-Sharp/blob/96e2905cab7bc6b33ac0a34ee5bb82ddccbcbb6c/Algorithms/Numeric/MillerRabinPrimalityChecker.cs#L15-L51","documentation":"The private Miller-Rabin helper IsProbablyPrimeNumber implements the randomized primality test, whose algorithm requires n > 3 (small values are handled by the public wrapper). It throws ArgumentException when n <= 3. This is an internal invariant; hitting it usually means the public entry point did not screen small inputs.","triggerScenarios":"The public primality-check path forwarding n <= 3 (e.g. 2, 3, 0, 1, or negatives) into IsProbablyPrimeNumber instead of short-circuiting them.","commonSituations":"Calling the checker with tiny numbers like 2 or 3 (which are prime by definition), 1, or negatives; or refactoring that bypasses the public wrapper's small-number handling.","solutions":["Handle n <= 3 at the call site: 2 and 3 are prime, 0, 1 and negatives are not; only pass n > 3.","Ensure you call the public API method rather than the private helper.","Pre-screen with a small table of primes/composites before the probabilistic test."],"exampleFix":"// before\nbool result = checker.IsProbablyPrimeNumber(candidate);\n// after\nbool result = candidate <= 3\n    ? candidate is 2 or 3\n    : checker.IsProbablyPrimeNumber(candidate);","handlingStrategy":"validation","validationCode":"bool IsPrimeSmall(long n) => n switch { 2 or 3 => true, <= 1 => false, _ => Checker.IsProbablyPrimeNumber(n) };","typeGuard":null,"tryCatchPattern":"try { return IsProbablyPrimeNumber(n, rounds, rand); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"more than 3\")) { return n is 2 or 3; }","preventionTips":["Short-circuit n <= 3 before the probabilistic test: 2,3 prime; 0,1,negative composite-by-definition","Always go through the public wrapper which handles small inputs","Cover tiny inputs (0,1,2,3,4) in primality unit tests"],"tags":["primality-test","argument-validation","csharp"],"backgroundTag":"value-out-of-range","analyzedSha":"96e2905cab7bc6b33ac0a34ee5bb82ddccbcbb6c","analyzedAt":"2026-09-13T17:04:01.438Z","contentChangedAt":"2026-09-13T17:04:01.438Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}