Number of loops of size k starting from a specific node | Return the Number of ways from a node to make a loop of size K in undirected complete connected graph of N nodes ; Driver code
function numOfways ( n , k ) { let p = 1 ; if ( k % 2 != 0 ) p = - 1 ; return ( Math . pow ( n - 1 , k ) + p * ( n - 1 ) ) / n ; } let n = 4 , k = 2 ; document . write ( numOfways ( n , k ) ) ;