Problem Statement
Percy would like to become the Penguin Emperor. First, he must go on a long journey to prove himself worthy.
There are several cities in Penguin Empire. All the cities lie on a circle around the great mountain. The cities are numbered 0 through numCities-1 in the clockwise direction around the mountain.
Percy lives in city 0 and that is where he will begin his journey. On the first day he will travel to a city adjacent to city 0. On the second day he will travel to another city two cities away from his current city. And so on: for each k, on the k-th day he will travel to a new city k cities away. Each day, Percy can choose a new direction of travel: either clockwise or counter-clockwise around the mountain.
You are given the
Definition
- Class:
- PenguinEmperor
- Method:
- countJourneys
- Parameters:
- int, long
- Returns:
- int
- Method signature:
- int countJourneys(int numCities, long daysPassed)
- (be sure your method is public)
Constraints
- numCities will be between 2 and 350, inclusive.
- daysPassed will be between 1 and 10^18, inclusive.
Examples
3
2
Returns: 2
There are two ways to have a Journey that returns home after two days. 0 -> 1 -> 0 where directions are CW-CW 0 -> 2 -> 0 where directions are CCW-CCW CW = clockwise CCW = counter-clockwise
4
3
Returns: 2
There are two ways to have a Journey that returns home after three days. 0 -> 1 -> 3 -> 0 where directions are CW-CW-CCW or CW-CCW-CCW 0 -> 3 -> 1 -> 0 where directions are CCW-CCW-CW or CWW-CW-CW CW = clockwise CCW = counter-clockwise
5
36
Returns: 107374182
300
751
Returns: 413521250
300
750
Returns: 0
350
1000000000000000000
Returns: 667009739
5
7
Returns: 12
350
576460752303423487
Returns: 157219053
51
3453
Returns: 681882592
350
51
Returns: 304806205
323
1
Returns: 0
323
3
Returns: 2
323
4
Returns: 2
323
5
Returns: 0
2
576460752303423487
Returns: 1
2
1000000000000000000
Returns: 1
2
100000000001
Returns: 0
3
100010100101
Returns: 301669435
350
788129934789836450
Returns: 0
349
785878134976151203
Returns: 909056360
2
1
Returns: 0
32
213412342314123
Returns: 453664493
342
12341243
Returns: 697501401
333
1212121212
Returns: 27013629
350
350
Returns: 0
350
349
Returns: 0
350
351
Returns: 310756132
2
2
Returns: 0
2
3
Returns: 1
2
4
Returns: 1
7
1234132481234323
Returns: 642755153
347
781374535348780709
Returns: 359419672
349
233
Returns: 713040368
201
514496860578435780
Returns: 988139060
310
883890419249926660
Returns: 667056628
116
824378772965568000
Returns: 740196544
85
744833315135881860
Returns: 524391913
91
431567805524141440
Returns: 418233654
88
602506188315165180
Returns: 860373109
58
454737952532060860
Returns: 260070945
253
130164509677965216
Returns: 703374640
290
30793709076387564
Returns: 947227231
246
745643484792426110
Returns: 0
200
25112172927
Returns: 847767337
259
10012503288
Returns: 12258986
120
43118587248
Returns: 716761497
222
18539410826
Returns: 0
251
65088042107
Returns: 495673673
322
1269521214
Returns: 0
262
8361710989
Returns: 0
150
16177337542
Returns: 0
146
38480129952
Returns: 221033522
224
11954975280
Returns: 189460651
15
79056
Returns: 601920383
45
63574
Returns: 500990433
201
98166
Returns: 300815399
51
80799
Returns: 703272657
244
55390
Returns: 0
5
38316
Returns: 354237861
124
79552
Returns: 716073185
189
12685
Returns: 271261413
130
43068
Returns: 923988205
29
57228
Returns: 38437960
338
206
Returns: 0
123
738
Returns: 333944189
78
376
Returns: 609529593
142
485
Returns: 0
82
274
Returns: 0
319
392
Returns: 811077399
36
739
Returns: 504483063
197
733
Returns: 341708807
229
980
Returns: 387321373
177
605
Returns: 604034094
51
51
Returns: 468609660
350
999999999999999999
Returns: 921915152
350
394064967394918050
Returns: 0
349
1000000000000000000
Returns: 96071113
350
788129934789836799
Returns: 861127998
350
985162418487295950
Returns: 0
3
3
Returns: 2
350
98516241848729250
Returns: 0