Number Theory | Generators of finite cyclic group under addition | Function to return gcd of a and b ; Print generators of n ; 1 is always a generator ; A number x is generator of GCD is 1 ; Driver Code
function gcd ( a , b ) { if ( a == 0 ) return b ; return gcd ( b % a , a ) ; } function printGenerators ( n ) { document . write ( " " ) ; for ( var i = 2 ; i < n ; i ++ ) if ( gcd ( i , n ) == 1 ) document . write ( i + " " ) ; } var n = 10 ; printGenerators ( n ) ;