factor

factor(n) -> Dict

Compute the prime factorization of an integer n. Returns a dictionary. The keys of the dictionary correspond to the factors, and hence are of the same type as n. The value associated with each key indicates the number of times the factor appears in the factorization.

julia> factor(100) # == 2*2*5*5
Dict{Int64,Int64} with 2 entries:
  2 => 2
  5 => 2

Examples

  1. Factorize an integer:

    julia> factor(100)
    Dict{Int64, Int64} with 2 entries:
     2 => 2
     5 => 2

    This example calculates the prime factorization of the integer 100 and returns a dictionary where the keys represent the factors and the values indicate the number of times each factor appears in the factorization.

  2. Factorize a large number:

    julia> factor(9876543210)
    Dict{Int64, Int64} with 4 entries:
     2 => 1
     3 => 2
     5 => 1
     3607 => 1

    It computes the prime factorization of a large number (9876543210 in this case) and returns a dictionary with the prime factors and their multiplicities.

  3. Factorize a prime number:
    julia> factor(17)
    Dict{Int64, Int64} with 1 entry:
     17 => 1

    When a prime number is provided, the function returns a dictionary with only one entry representing the prime factor itself.

Common mistake example:

julia> factor(0)
ERROR: DomainError("0 is not a positive integer.")

In this example, the input provided is not a positive integer, which results in a DomainError. The factor function expects a positive integer as input. Make sure to provide a valid positive integer to avoid such errors.

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: