Just put the input number into a binary array set, and replace all 1 via 4, then for even numbers, change the first value to 7.. that's all..