Wolfram Research

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 and Options

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

Examples

Basic Examples

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]=
In[4]:=
EulerPhi[10]
Out[4]=

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

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

Applications

The totatives of n form a multiplicative group modulo n:

In[6]:=
ResourceFunction["Totatives"]@24
Out[6]=

Here is its multiplication table:

In[7]:=
Mod[With[{n = 24}, Outer[Times, ResourceFunction["Totatives"]@n, ResourceFunction["Totatives"]@n]], 24] // Grid
Out[7]=

Requirements

Wolfram Language 11.3 (March 2018) or above

Resource History

License Information