HCF/LCM using prime factorisation