Write a C/C++ program to find generators of a cyclic group.

A cyclic group is a group that is generated by a single element. That means that there exists an element g, say, such that every other element of the group can be written as a power of g. This element g is the generator of the group. For example,


Input:  G=<Z6,+>
 
Output:
 
A group is a cyclic group with 2 generators.
g1 = 1 g2 = 5
 
 
Input:  G=<Z18,+>
 
Output:
 
A group is a cyclic group with 6 generators.
g1 = 1 g2 = 5 g3 = 7 g4 = 11 g5 = 13 g6 = 17

 
Implementation:

Following is the code to find the generators of a cyclic group in C:

Download  Run Code


Input:
 
G=<Z6,+>
G=<Z18,+>
G=<Z8,+>
G=<Z7*,*>
G=<Z18*,*>
 
Output:
 
G=<Z6,+>
G = {0,1,2,3,4,5}
The order of the group is 6.
 
order(0) = 1
order(1) = 6
order(2) = 3
order(3) = 2
order(4) = 3
order(5) = 6
 
A group is a cyclic group with 2 generators.
g1 = 1 g2 = 5
 
——————————————————————————————————————————————
 
G=<Z18,+>
G = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17}
The order of the group is 18.
 
order(0) = 1
order(1) = 18
order(2) = 9
order(3) = 6
order(4) = 9
order(5) = 18
order(6) = 3
order(7) = 18
order(8) = 9
order(9) = 2
order(10) = 9
order(11) = 18
order(12) = 3
order(13) = 18
order(14) = 9
order(15) = 6
order(16) = 9
order(17) = 18
 
A group is a cyclic group with 6 generators.
g1 = 1 g2 = 5 g3 = 7 g4 = 11 g5 = 13 g6 = 17
 
——————————————————————————————————————————————
 
G=<Z8,+>
G = {0,1,2,3,4,5,6,7}
The order of the group is 8.
 
order(0) = 1
order(1) = 8
order(2) = 4
order(3) = 8
order(4) = 2
order(5) = 8
order(6) = 4
order(7) = 8
 
A group is a cyclic group with 4 generators.
g1 = 1 g2 = 3 g3 = 5 g4 = 7
 
——————————————————————————————————————————————
 
G=<Z7*,*>
G = {1,2,3,4,5,6}
The order of the group is 6.
 
order(1) = 1
order(2) = 3
order(3) = 6
order(4) = 3
order(5) = 6
order(6) = 2
 
A group is a cyclic group with 2 generators.
g1 = 3 g2 = 5
 
——————————————————————————————————————————————
 
G=<Z18*,*>
G = {1,5,7,11,13,17}
The order of the group is 6.
 
order(1) = 1
order(5) = 6
order(7) = 3
order(11) = 6
order(13) = 3
order(17) = 2
 
A group is a cyclic group with 2 generators.
g1 = 5 g2 = 11

That’s all about finding generators of a cyclic group.