Did GCD algorithm