Find the value of n+n/2+n/3+n/4…+n/n?
N can have values ranging from 1 to 10^9.Only need to add the quotient of
each term and need not add the exact value.Example:5+5/2=7.Find the
fastest way to perform this addition and to be executed within 10^8
operations I have done this. I found that
1+1/2+1/3+1/4+1/5......<=1+1/2+(1/2)+(1/2).......So i found the nearest
2nd power to the n and add that much number of 1/2 to the solution.For
example if the value is 18,16 is the nearest power,so
n+n/2+n/3+n/4...+n/18 as n+n/2+n/2+n/2+(n/17+n/18).But the problem is it
doesn't work for bigger values.How to solve for bigger values ?
No comments:
Post a Comment