235 An Arithmetic Geometric sequence.gp 718 B

12345678910111213141516171819202122232425
  1. \\ Pari/GP
  2. \\ Daniel "Trizen" Șuteu
  3. \\ Date: 27 September 2017
  4. \\ https://github.com/trizen
  5. \\ https://projecteuler.net/problem=235
  6. \\
  7. \\ s(n) = sum((900-3k)*x^(k-1), {k=1..n})
  8. \\
  9. \\ We can easily derive a closed-form using Wolfram|Alpha:
  10. \\ http://www.wolframalpha.com/input/?i=sum((900-3k)*r%5E(k-1),+%7Bk%3D1..n%7D)
  11. \\
  12. \\ we get:
  13. \\ s(n) = (-3 * (n - 300) * x^(n + 1) + 3 * (n - 299) * x^n - 900*x + 897)/(x - 1)^2
  14. \\
  15. \\ Where, for `n=5000`, we have:
  16. \\ s(5000) = (-14100 * x^5001 + 14103 * x^5000 - 900*x + 897)/(x - 1)^2
  17. \\
  18. \\ Problem asks solving for `x`, such that `s(5000) = -600000000000`.
  19. \\
  20. print(solve(x=-1,2,(-14100 * x^5001 + 14103 * x^5000 - 900*x + 897)/(x - 1)^2 + 600000000000));