Count number of nodes in the cycle .
while ( vis [ j ] == 0 ) { vis [ j ] = 1 ; cnt ++ ; j = __gcd ( j , A [ j ] ) % n ; } } } } return cnt ; } function __gcd ( a , b ) { return b == 0 ? a : __gcd ( b , a % b ) ; }