Check every quadruplet pair whether its gcd is k
for ( int u = l ; u <= r ; u ++ ) { for ( int v = l ; v <= r ; v ++ ) { for ( int w = l ; w <= r ; w ++ ) { for ( int x = l ; x <= r ; x ++ ) { if ( __gcd ( __gcd ( u , v ) , __gcd ( w , x ) ) == k ) count ++ ; } } } }