Probelem Given a recurrence relation for gn as
g0 = c where is a contant double.
gn = f( gn-1 ) , where f is a linear function
then find the value of another recurrence given by
hn = gn/exp(n)
constraints: 1 <= n <= 10^9
Mathematically, the value of g(n) can be calculated in log(n) time and then h(n) can be calculated very easily but the problem is the overflow of doubles data types. So the above strategy works only for n around 1000 but not for bigger n. Note that value of h(n) can be well within the range of doubles
The actual problem is that we are trying to calculate h(n) from g(n). My question is that is there any good method to caculate h(n) directly without overflowing doubles.
G0=c
G1=ac+b
G2=a²c+ab+b
G3=a³c+a²b+ab+b
...
Gn=a^nc+b(a^n-1)/(a-1)
Then
Hn = (a/e)^nc+b((a/e)^n-1/e^n)/(a-1) ~ (a/e)^n (c + b/(a-1))