This is a math oriented algorithms puzzle.
Let φ be the golden ratio: 1+√52.
Consider the following sum
Sn=[φ]+[2φ]+⋯+[nφ]
i.e
Sn=n∑k=1[kφ]
where [x] is the integer part of x.
Can you give an algorithm to compute Sn that takes a polynomial in logn time?
[Solution]
Let φ be the golden ratio: 1+√52.
Consider the following sum
Sn=[φ]+[2φ]+⋯+[nφ]
i.e
Sn=n∑k=1[kφ]
where [x] is the integer part of x.
Can you give an algorithm to compute Sn that takes a polynomial in logn time?
[Solution]
No comments:
Post a Comment