Since we need powers of 10 for counting , it 's better to  pre store them along with their  modulo with 1e9 + 7 for counting
int st = 1 ; for ( int i = 0 ; i <= n ; i ++ ) { powers [ i ] = st ; st *= 10 ; st %= mod ; }