I tried it several times but wrong answer.

its running in all test cases i tried.

Can any1 provide me test cases where i go wrong?or any help…

my soln is:http://www.codechef.com/viewsolution/1725618

i have used a different method…

1.for prime,i used seive amd marked the numbers which are prime,then binary search to get the index or count of prime…

2.i am looping normally in 2d grid.

any number will have 4 neighbours.if we traverse the grid,cost of 3 neighbours of even/odd number will always have been calculated by now if we keep on marking even/odd neighbours and the cost of given server is known.further all its even/odd immediate neighbour which was not marked will be marked 0 now.

actually,if number is even,we find its 4 neighbours.if any neighbour is even and its answer matrix is marked we return 1.so the cost for arr*[j] server is 0.if none of its even neighbour is marked,

we mark their cost as 0 because the number which called them is even.

All i say that we dont need dfs.

just traverse grid and keep on marken neighbours.

its working fine.

can anybody help?

any test case…