recursive implementation
int GcdOfArray ( vector < int > & arr , int idx ) { if ( idx == arr . size ( ) - 1 ) { return arr [ idx ] ; } int a = arr [ idx ] ; int b = GcdOfArray ( arr , idx + 1 ) ; return __gcd ( a , b ) ; }