Problem Statement
Several years ago I was playing Spider Solitaire on my computer all the time. Sometimes I won, sometimes I lost. Then I stopped playing Spider Solitaire and started participating in programming competitions. After a few years I happened to start my old solitaire program again. I was pleased to discover that with the skill I gained during the years I am now able to win each and every game of Spider Solitaire. However, the program still remembers some of my previous games and thus the statistics don't necessarily reflect my current perfect skills.
The program displays the statistics in the following way:
Games played: X
Games won: Y (Z %)
The number Z is the percentage of games I won, rounded down to the nearest integer. For example, if X=53 and Y=47, then Z=88.
(The value Y/X is roughly equal to 0.8868, which means that I won roughly 88.68% of the games I played. 88.68% rounded down to an integer is 88%.)
You will be given two
Definition
- Class:
- ImprovingStatistics
- Method:
- howManyGames
- Parameters:
- int, int
- Returns:
- int
- Method signature:
- int howManyGames(int played, int won)
- (be sure your method is public)
Notes
- You may assume that the return value will always be less than 2,000,000,000.
Constraints
- played will be between 1 and 1,000,000,000, inclusive.
- won will be between 0 and played, inclusive.
Examples
10
8
Returns: 1
So far I won 8 games out of 10, and thus the displayed success percentage is 80%. After I win the next game the percentage will increase to 81%.
100
80
Returns: 6
Again, the currently displayed value is 80%. However, now I need to win at least 6 more games to bring it to 81%.
47
47
Returns: -1
Nothing left to improve.
99000
0
Returns: 1000
1000000000
470000000
Returns: 19230770
999999
999998
Returns: -1
1000000000
980000000
Returns: 1000000000
1000000000
974712345
Returns: 264382750
1000000000
979999999
Returns: 50
999997473
980123402
Returns: 987409627
1
0
Returns: 1
1
1
Returns: -1
2
0
Returns: 1
2
1
Returns: 1
2
2
Returns: -1
3
0
Returns: 1
3
1
Returns: 1
3
2
Returns: 1
3
3
Returns: -1
32532
3342
Returns: 266
23532532
3243243
Returns: 59665
754754632
52354643
Returns: 514174
476432567
0
Returns: 4812451
987654321
12
Returns: 9976295
100
99
Returns: -1
1000000000
980000000
Returns: 1000000000
1000000000
470000000
Returns: 19230770
10
0
Returns: 1
1000000000
990000000
Returns: -1
1000000000
999999999
Returns: -1
10000
9900
Returns: -1
100000
99999
Returns: -1
200
199
Returns: -1
1000000000
500000000
Returns: 20408164
1000000000
980000001
Returns: 999999900
47
46
Returns: 3
1000
9
Returns: 2
1750
1015
Returns: 43
908533084
907080095
Returns: -1
1000000000
989999999
Returns: 100
147974666
124825802
Returns: 6351094
101
100
Returns: -1
99
96
Returns: 1
1000000000
900000000
Returns: 111111112
1000
873
Returns: 59
200
198
Returns: -1
222
33
Returns: 1
1000000000
970000000
Returns: 500000000
1000000000
988000000
Returns: 200000000
100
98
Returns: 100
100000
98995
Returns: 500
1000
988
Returns: 200
1000000000
800000000
Returns: 52631579
1000
998
Returns: -1
10
1
Returns: 1
1000000
999999
Returns: -1
1000000000
3
Returns: 10101008
10000
9999
Returns: -1
10000000
9999999
Returns: -1
436134623
394732463
Returns: 23889377
1000000000
470000001
Returns: 19230768
999999999
980000000
Returns: 999999901
1000000000
0
Returns: 10101011
999999999
999999998
Returns: -1
500000
88888
Returns: 1357
1000
999
Returns: -1
843090428
556970660
Returns: 23939172
1000000000
989000000
Returns: 100000000
1
0
Returns: 1
2
1
Returns: 1
999
55
Returns: 6
10
10
Returns: -1
199999999
199999998
Returns: -1
1000000000
570000000
Returns: 23809524
5
1
Returns: 1