I have been attempting this British Informatics Olympiad question for many weeks now. I tried creating all plans but this would time out very easily (and take too much memory in some cases). I tried finding first plan and then counting up but this too would time out. I checked the sample tests and the biggest numbers they had were around 2^43, so I am not sure if they want a solution much better than that. Any help would be much appreciated.