factorIntegerPower

Writes an integer as a perfect power b^e with the largest possible exponent.

Category: Mathematics > Number Theory

Syntax

b = factorIntegerPower(n)

Returns the base b.

[b, e] = factorIntegerPower(n)

Returns the base and the exponent, with n = b^e.

Description

The function looks for the largest exponent e for which n is an exact e-th power. For n = 64 this gives b = 2 and e = 6, not 8^2. An integer that is not a perfect power, such as 360, returns itself with e = 1.

Negative inputs with an odd exponent give a negative base, since (-2)^3 = -8.

Input arguments

n
Integer scalar or array.

Output arguments

b
Base, with the same size as n.
e
Exponent, with the same size as n. It is 1 when n is not a perfect power.

Example

Perfect powers and a non-power

[b, e] = factorIntegerPower(64)
[b, e] = factorIntegerPower(100)
[b, e] = factorIntegerPower(360)
Output
b = 2
e = 6
b = 10
e = 2
b = 360
e = 1

See also

factor isprime nthroot eulerPhi