A solution to POJ 2309, bit operation