Find minimum GCD of all pairs in an array | Java program to find the minimum GCD of any pair in the array ; Function returns the minimum GCD of any pair ; Finding GCD of all the elements in the array . ; Driver code
import java . util . * ; class GFG { static int __gcd ( int a , int b ) { if ( b == 0 ) return a ; else return __gcd ( b , a % b ) ; } static int MinimumGCD ( int arr [ ] , int n ) { int g = 0 ; for ( int i = 0 ; i < n ; i ++ ) { g = __gcd ( g , arr [ i ] ) ; } return g ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 4 , 6 , 8 , 3 } ; int N = arr . length ; System . out . println ( MinimumGCD ( arr , N ) ) ; } }