If the question is: which door is the n

^{th}open door (for example tell me where the 5th open door is) then the answer is: n

^{2}or as per the example 5

^{2}=25 (the 25th door along is the 5th open door)

private static int NextOpenDoorIsAt(int nthOpenDoor)

{

return (int)Math.Pow(nthOpenDoor, 2d);

}

So in the case where you only need to find the n

^{th}door that is open this is a faster method. This of course could be applied to my previous post to give an O(√N) solution for the whole series - the faster being down to the speed of summation vs. product.

## No comments:

Post a Comment