Problem 3: Inquiry
https://open.kattis.com/problems/inquiryi
Trivial approach:
calculate the value for all separately
The time complexity is . Since , this is too slow
Hints:
Do we have to calculate every single time?
Can we store some intermediate value in so that we we can save ourselves some work for the next product?
Key idea:
Store as . Store as
For k= 1 ... n: we add to and subtract from .
Last updated