Seems to me it's got something to do with powers of 2.
He must have a bag with 1 coin in it - so that he can give you that bag if you ask for one coin.
He must also have one with 2 in it.
Doesn't need one with 3, because he coul give you Bag1 and Bag2.
Need a Bag4.
Don't need a 5 (Bag1 & Bag4) or 6 (Bag 2 and 4) or 7 (Bag3 and Bag4).
Need a Bag8.
Don't need 9,10,11,12,13,14,15 because these can be made up from the bags you already have.
Need a 16.
SO..... you need Bag1, Bag2, Bag4, Bag8, Bag 16 .... up to Bag 4096.
ie Bag (2^0), Bag(2^1), Bag(2^2) ....Bag(2^12)......ie 13 bags in all.