Problem is here:http://www.codechef.com/PRMT2014/problems/PROM01

Can Anyone tell me which previous problem is similar to this problem as well as how to derive formula for it?

The question is same as that of two queens problem(easiest sub problem of the n queen problem)ie placing 2 queens on a chess board such that they dont attack each other.

Here is the link for n queenâ€™s problem :http://www.geeksforgeeks.org/backtracking-set-3-n-queen-problem/

So you can apply a similar approach in this question. Instead of that i used PNC and got the formula for this question as number_of_ways=i.j.(j+i-2)+2.i.(i-1).(3.j-i-1)/3 (. means product)

Here is the link to my code: http://www.codechef.com/viewsolution/3766257

The approach of n queen will become very time consuming!could you give me the link to study the above formulae as i am not able to understand how it is derive?