The>desired result is to find the smallest value of g for which b>is an integer.>>Example: for n = 18 and q = 7, b = (1+5*18)/7 = 91/7 = 13, >so g = 5>>Best I have come up with so far is g<q and g*n mod q = q-1The conditions you came up with _uniquely_ determine the leastpositive integer g for which b is an integer.A fast method for finding g is the Euclidean algorithm.For example, using n = 18, q =