Algorithm with Math - GCD / LCM

Responsive image
source