Problem Statement
We have an infinite chess board, and a new type of chess piece called a "superking". It can perform two types of moves:
- Type-1: the normal king move - i.e., a move to a neighboring square in any of the eight directions horizontal, vertical or diagonal.
- Type-2: a move two squares to the left, right, up or down.
The superking begins at some square in the infinite board and performs type1 Type-1 moves and type2 Type-2 moves. Return the number of possible squares that the superking can reach after performing these moves.
Definition
- Class:
- Superking
- Method:
- squares
- Parameters:
- int, int
- Returns:
- long
- Method signature:
- long squares(int type1, int type2)
- (be sure your method is public)
Constraints
- type1 and type2 will be between 0 and 100000000 (108), inclusive.
Examples
0
0
Returns: 1
No moves are made, superking remains at the starting square.
1
0
Returns: 8
After one Type-1 move (normal king move), the superking can land in one of the 8 neighboring squares.
0
1
Returns: 4
After one Type-2 move, the superking lands in one of the four squares at a distance of 2 from the starting square (to the left, right, up or down).
1
2
Returns: 60
Let's assume that the superking starts at the red square at the center of the board shown below. After one Type-2 move, the superking can land in one of the blue squares. After the second Type-2 move, the superking can land in one of the red squares. After a final Type-1 move, the superking can land in any square neighboring a red square, i.e., one of the green squares. These are the possible final landing squares for the king after 1 Type-1 and 2 Type-2 moves, 60 in total (note that it is not important in which order we make the moves; here, we first did the two Type-2 moves and then the Type-1 move).
31
17
Returns: 14713
24
45
Returns: 35881
100000000
100000000
Returns: 280000000400000001
The maximum return value.
0
100000000
Returns: 10000000200000001
100000000
0
Returns: 40000000400000001
0
2
Returns: 9
0
10
Returns: 121
1
1
Returns: 28
1
5
Returns: 228
1
100000000
Returns: 60000001400000008
2
0
Returns: 25
2
1
Returns: 65
2
2
Returns: 121
2
7
Returns: 641
2
100000000
Returns: 80000003200000025
3
0
Returns: 49
3
1
Returns: 105
3
2
Returns: 177
3
3
Returns: 265
100000000
1
Returns: 40000002000000009
100000000
2
Returns: 40000003600000033
100000000
3
Returns: 40000005200000073
5
138
Returns: 163513
20
46761
Returns: 17507694169
57120
5183
Returns: 18002761353
7706765
1121940
Returns: 385991379582361
2
288491
Returns: 665825688385
24975
337
Returns: 2630676153
8
34539059
Returns: 9543577193843689
4726
79
Returns: 95382801
27
6
Returns: 5905
1
80
Returns: 39528
76
3772763
Returns: 113874512936569
673726
214
Returns: 1817936791401
9247633
963
Returns: 342217396349505
76207
86
Returns: 23335252225
5
23764455
Returns: 4517996472732721
1045420
318946
Returns: 10520348931729
5544
352
Returns: 155180961
94434984
35
Returns: 35671918073661801
26
5
Returns: 5089
27483522
3
Returns: 3021377355241153
56
44
Returns: 67681
4090
488
Returns: 100768633
20
2651
Returns: 57072409
26252026
10499
Returns: 2761086383594401
46976
241482
Returns: 656837351713
2120287
99
Returns: 17985834943641
26674
1790
Returns: 3635691961
579
5
Returns: 1389801
308
109
Returns: 1012889
3104
18
Returns: 39448225