divisors

All positive divisors of an integer.

Category: Mathematics > Formula Manipulation and Simplification

Syntax

d = divisors(n)

Returns the divisors of n in ascending order.

Description

The divisors are found from the prime factorization of n, so the cost depends on how hard n is to factor, not on its size alone. The list always starts with 1 and ends with abs(n).

Input arguments

n
Integer, numeric or symbolic. The sign is ignored.

Output arguments

d
Row vector: numeric when n is numeric, symbolic when n is symbolic.

Example

Numeric and symbolic input

divisors(12)
divisors(sym(30))
Output
ans = 1×6

     1     2     3     4     6    12
ans = 
[1, 2, 3, 5, 6, 10, 15, 30]

See also

factor primes isprime gcd nchoosek