Number of ways to place two queens on a N * N chess | Function to find number of valid positions for two queens in the N * N chess board ; Driver Code ; Function Call
function possiblePositions ( n ) { let term1 = Math . pow ( n , 4 ) ; let term2 = Math . pow ( n , 3 ) ; let term3 = Math . pow ( n , 2 ) ; let term4 = n / 3 ; let ans = ( Math . ceil ( term1 / 2 ) ) - ( Math . ceil ( 5 * term2 ) / 3 ) + ( Math . ceil ( 3 * term3 ) / 2 ) - term4 ; return ans ; } let n ; n = 3 ; let ans = possiblePositions ( n ) ; document . write ( Math . floor ( ans ) ) ;