Wolfram Computation Meets Knowledge

LargestPrimeFactor

Contributed by: Paco Jain (Wolfram Research)

Find the largest prime factor of a given integer

ResourceFunction["LargestPrimeFactor"][x]

finds the largest prime factor of an integer x.

Details and Options

ResourceFunction["LargestPrimeFactor"][0] returns 0. ResourceFunction["LargestPrimeFactor"][1] returns 1.
LargestPrimeFactor ignores the sign of the input; for negative x,ResourceFunction["LargestPrimeFactor"][x] is defined as equal to ResourceFunction["LargestPrimeFactor"][Abs[x]].

Examples

Basic Examples

Find the largest prime factor of a number:

In[1]:=
ResourceFunction["LargestPrimeFactor"][156]
Out[1]=

For non-numeric input, LargestPrimeFactor remains unevaluated:

In[2]:=
ResourceFunction["LargestPrimeFactor"][a + b]
Out[2]=

Scope

LargestPrimeFactor accepts any integer, including negatives and zero:

In[3]:=
ResourceFunction["LargestPrimeFactor"][-20]
Out[3]=
In[4]:=
ResourceFunction["LargestPrimeFactor"][0]
Out[4]=

Non-integer numeric input triggers a message:

In[5]:=
ResourceFunction["LargestPrimeFactor"][3/10]

Resource History