Блог пользователя caiocandido

Автор caiocandido, история, 8 лет назад, По-английски

Recently I was studying math and came across this problem:

Given 1 < a < 10, 1 <= n <= 100000, show how to compute the value of: 1 * a + 2 * a^2 + 3 * a^3 + ... + n * a^n efficienty, i.e. in O(log n)!

Could someone give ideas/way to solve this problem?

  • Проголосовать: нравится
  • +4
  • Проголосовать: не нравится

»
8 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Auto comment: topic has been updated by caiocandido (previous revision, new revision, compare).

»
8 лет назад, # |
Rev. 2   Проголосовать: нравится +4 Проголосовать: не нравится
Let S = 1 * a + 2 * a^2 + 3 * a^3 + ... + n * a^n   ... i
Then, a*S = 1*a^2 + 2*a^3 + ... + n*a^(n+1)         ... ii
Subtracting ii from i gives :-
(1-a)S = (a + a^2 + ... + a^n) - n*a^(n+1)
S = [(a + a^2 + ... + a^n) - n*a^(n+1)] / (1-a)

x1 = (a + a^2 + ... + a^n) = a*(1-a^(n-1))/(1-a)  (sum of geometric progression), &
x2 = n*a^(n+1)
So, the problem basically reduces to finding x^y which can be solved in O(log y) . 
»
6 лет назад, # |
  Проголосовать: нравится -21 Проголосовать: не нравится

FFT obviously!

»
6 лет назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

You can get the desired series by differentiating the general geometric sum formula and then multiplying both side by a

Also, this can be helpful somewhere (for example - 908D - New Year and Arbitrary Arrangement) -