Euclid-type algorithm and its applications