Problem Statement
Since hot debates arise on what numbers should be in S, the friends decided to regularize their choice. They always choose a contiguous interval of numbers [A, B] to be the initial collection S. That is, at the beginning of the game, the collection S contains each of the integers A through B, inclusive, exactly once. Manao knows that A and B will satisfy the condition L &le A &le B &le R. You are given the
Definition
- Class:
- TheDivisionGame
- Method:
- countWinningIntervals
- Parameters:
- int, int
- Returns:
- long
- Method signature:
- long countWinningIntervals(int L, int R)
- (be sure your method is public)
Notes
- Only one number from the collection changes in each move. For example, if the collection contains three copies of the number 8, and the player chooses X=8 and Y=4, only one of the 8s in the collection will change to a 2.
Constraints
- L will be between 2 and 1,000,000,000, inclusive.
- R will be between L and L + 1,000,000, inclusive.
Examples
9
10
Returns: 2
If the chosen interval is [9,9] or [10,10], the collection S contains only one number. In these two situations Manao can win the game in a single move. On the other hand, if the chosen interval is [9,10], Manao will lose to an optimally playing opponent.
2
5
Returns: 9
The only case where Manao loses is if the game starts with the interval [2,3]. Note that if the starting interval is [2,5], Manao can choose X=4 and Y=2 in his first move. After that move, the collection will contain the values 2, 2, 3, and 5.
2
6
Returns: 13
Manao will also lose the game if the starting interval is [3,6].
2
100
Returns: 4345
2
1000000
Returns: 484332732439
999805519
1000072678
Returns: 34556370200
322182648
322366988
Returns: 16458568846
972332890
972991678
Returns: 210198241511
621951803
622514232
Returns: 153220984390
439994515
440256601
Returns: 33270043250
246393079
247097102
Returns: 240055105607
735723387
735981106
Returns: 32159046732
136622599
137301388
Returns: 223179003425
995729871
995999472
Returns: 35186785054
928521092
929178016
Returns: 209018892540
313049587
313806848
Returns: 277610201814
306324944
306741607
Returns: 84047562501
917527876
918390177
Returns: 360158429580
498758103
499481464
Returns: 253450583775
124459316
125179275
Returns: 251059459794
277598778
278295907
Returns: 235386888210
787264027
787293044
Returns: 406583323
452363613
452697481
Returns: 53987632578
513997053
514233830
Returns: 27145496229
519831547
520505144
Returns: 219777996483
963150948
963191500
Returns: 794716297
823418002
824138375
Returns: 251360267051
121125910
121159002
Returns: 530168251
304949729
305059410
Returns: 5795337874
581905907
582132507
Returns: 24769134983
690179303
690871331
Returns: 231936917782
498892693
499771152
Returns: 373788102163
739417415
740072972
Returns: 208101472766
59514906
60026429
Returns: 126730757152
15950270
16496160
Returns: 144341568064
1000000000
1001000000
Returns: 484283198296
1000000000
1000999999
Returns: 484282227087
999992337
1000735125
Returns: 267186927998
1769231
2042041
Returns: 35967574613
227633262
228191236
Returns: 150789097552
78813294
79619929
Returns: 315164873645
5532558
6305121
Returns: 289100669074
316885025
317516761
Returns: 193303790510
244051794
244640881
Returns: 168083555209
860698463
861305104
Returns: 178256637164
996513632
996980625
Returns: 105625900802
301279250
301508496
Returns: 25446777025
374189411
374577316
Returns: 72798202317
9236217
9840769
Returns: 177019805409
94047129
94167616
Returns: 7031495982
45187085
45576001
Returns: 73250601799
633980676
634636864
Returns: 208556568290
19576505
20169081
Returns: 169857904630
10038384
10556001
Returns: 129749022173
361707707
361912576
Returns: 20323479752
427665693
428407204
Returns: 266258283474
414586888
415344400
Returns: 277800445017
9969942
10310521
Returns: 56089594166
12566125
12567777
Returns: 1313432
999999888
1000999888
Returns: 484283199243
999000000
1000000000
Returns: 484361741725
1000000000
1000900000
Returns: 392269511489
999999999
1000999333
Returns: 483636599604
999000001
1000000000
Returns: 484360773690
900000000
901000000
Returns: 484204626300
101000001
102000000
Returns: 484227486489
724313112
725313112
Returns: 484374259067