algorithm - Sum of the largest odd divisors of the first n numbers -


I've been working on topcoder recently and I'm stumbling on this question that I can not understand . The question is that F (n) = F (1) + F (2) + ... F (n) is the biggest odd separator for a given "n" like F (n) n. There are many trivial solutions for the answer; However, I found this solution very interesting.

  int compute (n) {if (n == 0) 0; Long k = (n + 1) / 2; Return k * k + calculation (n / 2); }  

However, I do not understand how to get a recurring relation from the statement of such a problem. Can anyone help this?

I believe they are trying to use the following facts:

<(2k + 1) = 2k + 1, that is the largest odd separator number of a strange number.
  • f (2k) = f (k) i.e. that is the largest odd dividend number of a number 2m, similar to the largest severance separator of M.
  • The sum of the first Kashmir numbers is equal to k ^ 2.
  • Now {1,2, ..., 2m + 1} to {1,3,5,7, ...} and {2,4,6, ... , 2m} and try to apply the above facts.


    Comments