Codeforces Round #181 Problem C Beautiful Numbers