How to solve HDU 6063 problem involving RXD and mathematical concepts?