the key of your 2nd step is actually because 2^n - 2^m <> 10 ^n (n>=2)!. in plain language: you can never mess 1 hat but get the same last 2 digits.
Now remember it actually also right 2^n - 2^m <> 1 . you can never mess up 1 hat but get the same last 1 digit!.
So, 第3步 ~~~
- you only need to know the last ONE digit and 会发现只有 ONE arrangement可以由汇总得到的2进制数通过转换1位数字得到... 99.1% now!
....
Now 第4步
...
...
...
...
note: let's say n= # of colors...
now if going through the long way and hard way (马后炮 though), we do not need to trap ito the 2进制 <-> n进制 and you can eliminated the 进制transitions and exclusions.... Use n 进制 directly - that's the final simple and sweet answer posted earlier!
:)