use GCD of array to solve it elegant, refer to other's algorithm, good