Minimum moves taken to move coin of each cell to any one cell of Matrix | Java program to find the minimum number of moves taken to move the element of each cell to any one cell of the square matrix of odd length ; Function to find the minimum number of moves taken to move the element of each cell to any one cell of the square matrix of odd length ; Initializing count to 0 ; Number of layers that are around the centre element ; Iterating over ranger of layers ; Increase the value of count by 8 * k * k ; Driver code
class GFG { public static int calculateMoves ( int n ) { int count = 0 ; int layers = n / 2 ; for ( int k = 1 ; k < layers + 1 ; k ++ ) { count += 8 * k * k ; } return count ; } public static void main ( String [ ] args ) { int N = 5 ; System . out . println ( calculateMoves ( N ) ) ; } }