Ways to place 4 items in n ^ 2 positions such that no row / column contains more than one | Java implementation of the approach ; Function to return the number of ways to place 4 items in n ^ 2 positions ; Driver code
class GFG { static long NumberofWays ( int n ) { long x = ( 1l * ( n ) * ( n - 1 ) * ( n - 2 ) * ( n - 3 ) ) / ( 4 * 3 * 2 * 1 ) ; long y = ( 1l * ( n ) * ( n - 1 ) * ( n - 2 ) * ( n - 3 ) ) ; return ( 1l * x * y ) ; } public static void main ( String args [ ] ) { int n = 4 ; System . out . println ( NumberofWays ( n ) ) ; } }