gcd without recursion and mod