Function Repository Resource:

PerfectPowerQ

Source Notebook

Determine whether a given integer is a perfect power

Contributed by: Swastik Banerjee

ResourceFunction["PerfectPowerQ"][n]

yields True if n can be represented as a perfect power of a some integer greater than 1 and False otherwise.

ResourceFunction["PerfectPowerQ"][n,k]

yields True if n is the kth power of some integer greater than 1 where k2.

Details and Options

An integer n is a perfect power if there exist integers x and k such that xk=n, where x,k2.
An integer has a perfect power if the set of exponents in its prime factorization have a GCD greater than one.

Examples

Basic Examples (1) 

Test whether 100 can be expressed as a perfect power:

In[1]:=
ResourceFunction["PerfectPowerQ"][100]
Out[1]=

Scope (1) 

List of all perfect powers up to 105:

In[2]:=
Select[Range[2, 10^5], ResourceFunction["PerfectPowerQ"]]
Out[2]=

Options (1) 

When a second argument k is passed, PerfectPowerQ checks whether n can be represented as the perfect kth power of some integer greater than one:

In[3]:=
ResourceFunction["PerfectPowerQ"][27, 3]
Out[3]=

Applications (1) 

The first few perfect powers without duplications are 1, 4, 8, 9, 16, 25, 27, 32, 36, 49, 64, 81, 100, 121, 125, … (OEIS A001597). Even more amazingly, the sum of the reciprocals of these numbers (excluding 1) is given by (OEIS A072102), where μ(k) is the Möbius function (MoebiusMu) and ζ(k) is the Riemann zeta function (Zeta).

This can be verified with the PerfectPowerQ function:

In[4]:=
CalculateSum[1] = 0;
CalculateSum[2] = 0;
CalculateSum[n_] := CalculateSum[n] = CalculateSum[n - 1] + Boole[ResourceFunction["PerfectPowerQ"][n]]/n
In[5]:=
ListPlot[Table[CalculateSum[x], {x, 2, 100000}], PlotRange -> All]
Out[5]=

Possible Issues (2) 

The first argument should be an integer greater than 1:

In[6]:=
ResourceFunction["PerfectPowerQ"][-100]
Out[6]=

The second argument, if given, should be greater than or equal to 2:

In[7]:=
ResourceFunction["PerfectPowerQ"][20, 1]
Out[7]=

Properties and Relations (1) 

PerfectPowerQ of a prime number always yields False:

In[8]:=
ResourceFunction["PerfectPowerQ"][17]
Out[8]=

Publisher

Wolfram Summer School

Version History

  • 1.0.0 – 25 September 2020

Source Metadata

Related Resources

License Information