gcd
Euclid’s algorithm: gcd of 2 number equals gcd of smaller number and their difference. Use Euclid’s algorithm to calculate gcd(a, b). package com.pli.project.algorithm.gcd; import java.math.BigInteger; /** * Created by lipeng on 2015/5/23. */ public class Gcd { /** * Keep a is the max value. * gcd{a,b}=gcd{−a,b}=gcd{a,−b}=gcd{−a,−b} * https://proofwiki.org/wiki/GCD_for_Negative_Integers */ public static int gcd(int a, int… Read More »