you remember once we are talking about algo with O(1/n) complexity . see his solution is little similar to that XD.

# ADAROKS2 - a solution discussion

**karangreat234**#23

Lololololol, I am the famous creator of O(1/N) algorithm which can be applied to any problem. I guess it has been leaked

**karangreat234**#26

Here is the unofficial editorial for ADAROOKS:- Unofficial Editorial for ADAROOKS2-MAY-2019-LONG-CHALLENGE

**daman1209arora**#29

I came upon a mathematical generalisation to this.

There always exists such a way of placing rooks such that there are p^3 rooks in a p^2*p^2 board where p is a prime. This relies heavily on modular arithmetic. The basis idea to be considered it is that the set a.x mod p where x varies from 0 to p-1 comprises of all numbers between 0 and p-1 when a is co-prime to p.

Using this, I pre-computed solutions for 121, 169, 361 and 1369. Then, I crop out the first n^2 elements from whichever pre-computed solution is necessary.

https://www.codechef.com/viewsolution/24207746

Just in case someone wants a look.