X

DAYS

:

HOUR

:

MINS

:

SEC

#### Loading...

Copied to Clipboard
Lottery Money
Basic Accuracy: 72.96% Submissions: 70 Points: 1

There is a game "Choose a number and win money", in which, a person playing a game has to select a number N and he/she will be awarded some money in Rupees accordingly. Some of the observations of selecting a number N and money awarded(M) are:-

N: 1   2   3   4   5   6   7   8   9   10   11   12   13   14   15   16   17   18   19   20   21   22   23   24 ..........

M: 3   2   1   6   5   4   3   2   1   12   11   10   9     8     7      6      5     4     3    2     1    24  23  22...............

i.e. if you selects a number N=1,she gets M=Rs 3,if N=2,M=Rs 2,if N=3 ,M=Rs 1 and so on..

Example 1:

Input:
N = 30
Output:
16
Explanation:
As per the distribution,
you earn Rs 16.

Example 2:

Input:
N = 1
Output:
3
Explanation:
As per the distribution,
you earn Rs 3.

Your Task:

You don't need to read input or print anything. Your task is to complete the function totalMoney() which takes an integer N and returns total money.

Expected Time Complexity: O(log(N))
Expected Auxiliary Space: O(1)

Constraints:
1<=N<=109

We are replacing the old Disqus forum with the new Discussions section given below.
Click here to view old Disqus comments.

to report an issue on this page.

### Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

#### My Submissions:

Login to access your submissions.

Lottery Money