text: Number of loops of size k starting from a specific node | Java Program to find number of cycles of length k in a graph with n nodes . ; 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
code: public class GFG { static int numOfways ( int n , int k ) { int p = 1 ; if ( k % 2 != 0 ) p = - 1 ; return ( int ) ( Math . pow ( n - 1 , k ) + p * ( n - 1 ) ) / n ; } public static void main ( String args [ ] ) { int n = 4 , k = 2 ; System . out . println ( numOfways ( n , k ) ) ; } }