TopcoderArchive
SRM23 Sep 2009
SRM 449

OddDivisors

Problem statement, definition, constraints, and public examples.

Problem Statement

Let f(x) be the greatest odd divisor of x, where x is a positive integer. You are given a positive integer N. Return f(1)+f(2)+…+f(N).

Definition

Class:
OddDivisors
Method:
findSum
Parameters:
int
Returns:
long
Method signature:
long findSum(int N)
(be sure your method is public)

Constraints

  • N will be between 1 and 1000000000, inclusive.

Examples

  1. 7
    Returns: 21
    f(1)+f(2)+f(3)+f(4)+f(5)+f(6)+f(7)=1+1+3+1+5+3+7=21
  2. 1
    Returns: 1
  3. 777
    Returns: 201537
Back to all problems