Problem Statement
- Each square is aligned to the sides of the board and exactly one of its vertices coincides with a vertex of the board.
- The length of the side of each of the squares is a positive integer.
- No pair of squares intersects. Note that some pairs of squares may touch each other.
Manao is interested in how many ways can he choose the lengths of the sides for his squares. More precisely, he is interested in the number of quadruples (a, b, c, d) such that if the square in the top-left corner of the board has side length a, the square in the bottom-left corner has side length b, the square in the top-right corner has side length c and the square in the bottom-right corner has side length d, they do not intersect.
You are given the
Definition
- Class:
- TheFourSquares
- Method:
- countPlacements
- Parameters:
- int, int
- Returns:
- int
- Method signature:
- int countPlacements(int n, int m)
- (be sure your method is public)
Constraints
- n will be between 2 and 1,000,000, inclusive.
- m will be between 2 and 1,000,000, inclusive.
Examples
2
2
Returns: 1
The only valid quadruple is (1, 1, 1, 1).
3
3
Returns: 5
The five valid quadruples are: (1, 1, 1, 1). (1, 1, 1, 2). (1, 1, 2, 1). (1, 2, 1, 1). (2, 1, 1, 1).
3
4
Returns: 9
In addition to the five quadruples from the previous sample, there are four new quadruples here: (1, 2, 1, 2). (1, 2, 2, 1). (2, 1, 1, 2). (2, 1, 2, 1).
10
7
Returns: 421
123456
987654
Returns: 136415012
1000000
1000000
Returns: 260122732
1000000
999999
Returns: 93122718
999999
1000000
Returns: 93122718
999999
999999
Returns: 758109197
2
1000000
Returns: 1
989782
1000000
Returns: 914669749
739798
669212
Returns: 311761403
292586
424235
Returns: 307328095
805115
938417
Returns: 822799866
384500
259574
Returns: 375888347
356807
796049
Returns: 290933291
260731
777351
Returns: 434922109
109230
690343
Returns: 845965649
586570
163882
Returns: 389920628
57710
949982
Returns: 718492866
61923
217062
Returns: 626354668
106493
909559
Returns: 603935003
417580
781770
Returns: 14636816
97278
301791
Returns: 844654655
199923
179248
Returns: 490242682
788621
549059
Returns: 28850380
417438
359410
Returns: 335668543
448742
797672
Returns: 832492533
542729
440909
Returns: 655163055
821554
551577
Returns: 827594240
28734
632885
Returns: 797067487
281345
106952
Returns: 835197208
194181
142686
Returns: 949365357
578515
115113
Returns: 914743886
60804
565419
Returns: 104572100
696888
508387
Returns: 800669939
483692
424084
Returns: 833708597
992554
712067
Returns: 89878021
706108
983116
Returns: 356388798
964869
535314
Returns: 229267154
291492
193513
Returns: 424105565
722130
384820
Returns: 485933304
237812
644351
Returns: 939244589
447623
477308
Returns: 807142952