solved GCD method