Simplify the solution for group a sequence a little bit.
Review euclid gcd algorithm, you don't have to find the order of two numbers to use euclid algorithm.