Define a function f mapping positive integers to positive integers by f(1)=1, and f(n)=f(n-1)+n if f(n-1)<=n
and f(n)=f(n-1)-n if f(n-1)>n
For n≥2,
i) Find the smallest integer n such that f(n) = 1,000,000
ii) Find the smallest integer n such that f(n) = 2,000,000
we can use generating functions to solve this problem. If we allowed leading zeros then we could simply use the coefficient of x^45 from the expansion of (1+x+x^2+...+x^9)^10 which turns out to be 432457640. To eliminate those which have leading zeros we can subtract the coefficient of x^45 from (1+x+x^2+...+x^9)^9 which is 40051495 (
friday night funkin mod game).
Subtracting these two we get
432457640-40051495=392406145
so there are 392,406,145 such 10-digit numbers