Python, 116 bytes
Takes input a decimal number as a string, while using a recursive function to calculate the first n primes and the proposed equation of user GotCubes.
f=lambda n,i=1,p=1:n*[0]and p%i*[i]+f(n-p%i,i+1,p*i*i) c=lambda s:sum(y*(9-x)for x,y in zip(map(int,s),f(len(s))))+1