Problem Statement
When trying to divide coins "equally" between two people, an old gag goes something like this...
- The person dividing up the loot says "One for you, and one for me" giving one coin to the other person and then themselves.
- Next they say "And that's two for you", while giving the other person a second coin.
- Then, they say "And that's one, two, for me", giving themselves two coins, additional to the first one they already had.
- Then, they say "That's three for you, and one, two, three, for me", given the other person a third coin before giving themselves three more coins.
- ... and so on
The are N coins to be divided. Assuming they are divided in this sneaky fashion, how many coins will the first person end up getting?
Definition
- Class:
- OneForYou
- Method:
- coinCount
- Parameters:
- long
- Returns:
- long
- Method signature:
- long coinCount(long N)
- (be sure your method is public)
Constraints
- N will be between 0 and 10^15, inclusive.
Examples
2
Returns: 1
In this case, it's actually fair, each person gets one coin.
9
Returns: 6
This is three full rounds of dividing coins.
11
Returns: 7
Here we run out of coins before the person dividing the coins takes four of them, so he takes as many as he can.
33
Returns: 26
1000000000
Returns: 999955280
1000000000000000
Returns: 999999955278641
12345678901234
Returns: 12345673932195
0
Returns: 0
1
Returns: 0
99999999999999
Returns: 99999985857864
100000000000000
Returns: 99999985857865
999999999999999
Returns: 999999955278640
10000000000
Returns: 9999858580
1000000001
Returns: 999955281
234124152345436
Returns: 234124130706391