Function Repository Resource:

Totatives

Source Notebook

Get the integers from 1 to n that have no common proper factor with n

Contributed by: George Beck

ResourceFunction["Totatives"][n]

gives the numbers in the range 1 to n that are relatively prime to n.

Details

The number of totatives of n is the totient function of n, given by EulerPhi[n].

Examples

Basic Examples (2) 

The GCDs of these numbers with 10 is 1:

In[1]:=
ResourceFunction["Totatives"][10]
Out[1]=
In[2]:=
GCD[#, 10] & /@ Range[10]
Out[2]=
In[3]:=
Position[%, 1]
Out[3]=

The length of the result of Totatives is given by EulerPhi:

In[4]:=
EulerPhi[10]
Out[4]=

Applications (2) 

The totatives of n form a multiplicative group modulo n:

In[5]:=
ResourceFunction["Totatives"][24]
Out[5]=

Here is its multiplication table:

In[6]:=
With[{n = 24},
 tl = ResourceFunction["Totatives"][n];
 ResourceFunction["PrettyGrid"][Mod[Outer[Times, tl, tl], n], "ColumnHeadings" -> tl, "RowHeadings" -> tl, PlotTheme -> "Minimal"]]
Out[6]=

Neat Examples (1) 

This plots the totative of n above (n,0), for n = 1,2,,40:

In[7]:=
Graphics[
 Table[Point[{n, #} & /@ ResourceFunction["Totatives"][n]], {n, 40}]]
Out[7]=

Requirements

Wolfram Language 11.3 (March 2018) or above

Version History

  • 2.0.1 – 20 September 2021
  • 2.0.0 – 19 April 2019
  • 1.0.0 – 11 February 2019

Related Resources

License Information