Problem Statement
Each cell contains a single mirror. Seen from above, the mirror is a segment that connects two opposite corners of the cell. The mirror surface is on both sides of the segment. (Note that for each cell there are two possible positions of the mirror.)
Cat Upper has a laser which can be used to cast rays. When casting a ray, the following rules must be obeyed:
- The ray must be cast from outside of the black box.
- The ray must enter the box exactly in the middle of a side of a cell.
- The ray must enter the box in the direction perpendicular to the side of the box it enters through.
Once inside the box, the laser follows the laws of reflection: it travels in a straight line through open space, and it reflects whenever it hits a mirror. (Note that this means that the laser will always travel in a direction parallel to one of the sides of the box.)
The process ends when the ray exits the black box. (Note that this always has to happen, and that the ray will necessarily leave through the middle of some other cell wall.)
Cat Upper used the laser to cast a ray through each of the 2N+2M cell sides that were visible from the outside. For each cell side C, Upper recorded where the laser that entered through C exited the black box.
Afterwards, Upper removed a single mirror from the grid and repeated the entire experiment. Surprisingly, the results were completely identical to the first experiment.
Cat Upper has lost the black box and he does not remember the cell from which he removed the mirror. The only thing he remembers are the dimensions of the black box.
You are given the two
Definition
- Class:
- BlackBoxDiv1
- Method:
- count
- Parameters:
- int, int
- Returns:
- int
- Method signature:
- int count(int N, int M)
- (be sure your method is public)
Constraints
- N will be between 1 and 200, inclusive.
- M will be between 1 and 200, inclusive.
Examples
2
2
Returns: 5
There are 5 possible patterns. In the leftmost configuration Upper could remove any of the four mirrors. In each of the other four configurations, Upper can remove the mirror that does not touch the other three mirrors.
1
1
Returns: 0
3
5
Returns: 32478
194
197
Returns: 647560542
1
200
Returns: 0
200
1
Returns: 0
200
200
Returns: 137974162
16
42
Returns: 786980056
144
139
Returns: 274270453
115
116
Returns: 291753185
194
175
Returns: 962856170
96
182
Returns: 934932818
107
162
Returns: 839704822
41
184
Returns: 147033874
38
191
Returns: 92361539
94
115
Returns: 161477449
180
162
Returns: 263123427
46
125
Returns: 215880163
131
26
Returns: 658892131
104
47
Returns: 453883689
131
77
Returns: 468126505
177
32
Returns: 948327117
85
30
Returns: 721386154
77
160
Returns: 268888578
147
2
Returns: 604537113
33
161
Returns: 595287717
9
139
Returns: 703169625
126
93
Returns: 366338278
37
164
Returns: 419791043
160
101
Returns: 76061187
130
189
Returns: 590139417
189
163
Returns: 121702483
191
146
Returns: 67718337
84
45
Returns: 656025807
99
169
Returns: 633244121
6
189
Returns: 715824080
159
50
Returns: 250226581
91
157
Returns: 835810290
2
122
Returns: 600392459
82
136
Returns: 767074861
132
185
Returns: 304365292
63
54
Returns: 405928991
151
24
Returns: 92382126
68
135
Returns: 323797276
20
44
Returns: 218442994
48
152
Returns: 114158329
113
116
Returns: 867461667
97
56
Returns: 69299284
127
113
Returns: 44517943
192
177
Returns: 636985790
81
187
Returns: 140686105
54
147
Returns: 258123736
178
96
Returns: 817157123
124
28
Returns: 532618572
25
53
Returns: 713835489
9
96
Returns: 982266800
190
158
Returns: 100433629
5
5
Returns: 33553306
2
200
Returns: 201187467
3
200
Returns: 151414239
200
2
Returns: 201187467
200
3
Returns: 151414239