What is the method to solve ANUBGC?

How do we calculate the number of numbers less than N which contain a certain digit ‘d’, within time limit?


@anudeep2011 : please answer the approach to solve the question.

Editorial can be found here - http://discuss.codechef.com/questions/43055/anubgc-editorial

If you have doubts in the Editorial, please comment there it self.