Finishing relatively prime boolean matrix and modified gcd function