Function Repository Resource:

LargestPrimeFactor

Source Notebook

Find the largest prime factor of a given integer

Contributed by: Wolfram|Alpha Math Team

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.
ResourceFunction["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 (2) 

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 (2) 

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]

Publisher

Wolfram|Alpha Math Team

Version History

  • 2.0.0 – 06 September 2019
  • 1.0.0 – 16 January 2019

Related Resources

License Information