Exactly right, UFP2161. I changed my terminating condition and it worked like a charm. Thanks a lot.
In my defense, the judge gets mad when submissions generate answers with extraneous whitespace, so I don't think it's right that the judge's input files have extra whitespace in them. Gar.
Yay, I just solved this problem. Much credit goes to Marteen for his test cases. However, a number of them are invalid inputs, and I thought I'd clean up the list a little bit.
100 1 1000 1 10000 1 The above three are invalid because neither 100, 1000, nor 10000 = 2^x for any x (the base of the ...