Main Content

factorIntegerPower

Perfect power factoring

Description

example

x = factorIntegerPower(n) factors the number n into its perfect power xk and returns the base x. If several perfect powers exist, x is returned for maximum k. The function factorIntegerPower acts element-wise on array input.

example

[x,k] = factorIntegerPower(n) returns both the base x and power k.

Examples

collapse all

Factor 64 into its perfect power. If several perfect powers exist for a number, the maximum k is returned.

n = 64;
[x,k] = factorIntegerPower(n)
x =
     2
k =
     6

Find perfect powers of 7, 841, and 2541865828329.

n = [7 841 2541865828329];
[x,k] = factorIntegerPower(n)
x =
     7    29     3
k =
     1     2    26

Reconstruct the numbers. Return exact symbolic integers instead of floating point by converting x to symbolic form.

sym(x).^k
ans =
[ 7, 841, 2541865828329]

If a number is not a perfect power, factorIntegerPower returns the number itself as the base with exponent 1. So, a number is a perfect power if it does not equal its base.

Check if 125 is a perfect power. isequal returns logical 0 (false), meaning 125 is not equal to the returned base. Therefore, 125 is a perfect power.

n = 125;
isequal(n,factorIntegerPower(n))
ans =
  logical
   0

Input Arguments

collapse all

Input, specified as a number, vector, matrix, array, or a symbolic number or array. n must be a positive integer.

Output Arguments

collapse all

Base in perfect power, returned as a number, vector, matrix, array, or a symbolic number or array.

Power in perfect power, returned as a number, vector, matrix, array, or a symbolic number or array.

Version History

Introduced in R2018a

See Also