CODECHEF - Chef and Digits (April Challenge 2014)

http://www.codechef.com/APRIL14/problems/ADIGIT/