question link : https://www.spoj.com/problems/NUMTSN/
I’ve not solved this problem, but it looks like a Digit DP to me.