Here you can find the source of gcdUsingRecursion(long a, long b)
Parameter | Description |
---|---|
a | Long integer |
b | Long integer |
public static long gcdUsingRecursion(long a, long b)
//package com.java2s; //License from project: Apache License public class Main { /**//from w ww. j a v a2s . c o m * Calculate greatest common divisor of two numbers using recursion. * <p> * Time complexity O(log(a+b)) * <br> * @param a Long integer * @param b Long integer * @return greatest common divisor of a and b */ public static long gcdUsingRecursion(long a, long b) { a = Math.abs(a); b = Math.abs(b); return a == 0 ? b : gcdUsingRecursion(b % a, a); } }