primes

primes([lo,] hi)

Returns a collection of the prime numbers (from lo, if specified) up to hi.

Examples

  1. Generate prime numbers up to a given limit:

    julia> primes(20)
    8-element Array{Int64,1}:
    2
    3
    5
    7
    11
    13
    17
    19

    The primes function returns an array of prime numbers up to the specified limit (inclusive). In this example, prime numbers up to 20 are generated.

  2. Generate prime numbers within a specific range:

    julia> primes(10, 30)
    6-element Array{Int64,1}:
    11
    13
    17
    19
    23
    29

    By providing both the lower limit (lo) and the upper limit (hi), the primes function generates prime numbers within the specified range.

  3. Handle cases with no prime numbers in the range:
    julia> primes(30, 40)
    0-element Array{Int64,1}

    When there are no prime numbers within the specified range, an empty array is returned.

Common mistake example:

julia> primes(-5)
ERROR: ArgumentError: `lo` must be a non-negative integer

In this example, a negative value is provided for the lo argument. The lo argument must be a non-negative integer. Make sure to provide valid inputs to the primes function.

See Also

abs2, beta, binomial, ceil, cell, cross, ctranspose, ctranspose!, cummin, cumprod, cumprod!, cumsum, cumsum!, cumsum_kbn, div, divrem, eigfact, eigfact!, eigmin, eps, erf, erfc, erfcinv, erfcx, erfi, erfinv, exp, exp10, exp2, expm1, exponent, factor, factorial, factorize, floor, gcd, invmod, log, log10, log1p, log2, logspace, max, min, mod, mod1, modf, next, nextpow, nextprod, num, primes, primesmask, prod, realmin, sqrt, sum!, sumabs, sumabs!, sumabs2, sumabs2!,

User Contributed Notes

Add a Note

The format of note supported is markdown, use triple backtick to start and end a code block.

*Required Field
Details

Checking you are not a robot: