Connection Status:
Competition Arena > OddDivisors
SRM 449 · 2009-09-23 · by dzhulgakov · Recursion, Simple Math
Class Name: OddDivisors
Return Type: long
Method Name: findSum
Arg Types: (int)
Problem Statement

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).

Constraints

  • N will be between 1 and 1000000000, inclusive.
Examples
0)
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

1)
1
Returns: 1
2)
777
Returns: 201537
3)
1000000000
Returns: 333333333334181226
4)
999999999
Returns: 333333333332228101

Submissions are judged against all 59 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class OddDivisors with a public method long long findSum(int N) · 59 test cases · 2 s / 256 MB per case

Submitting as anonymous