Statement

## Goal

Pirx the Pilot is flying his spaceship through hyperspace in search of gold. Given a 5D realm with all dimensions ranging from 1 to N, each location (x,y,z,w,v) is either a chest of gold (1) or a barrier (0) as determined by the function:

f(x,y,z,w,v)=isprime(1+ mod(x*y*z*w*v,C))

The barriers form rooms in hyperspace (Pirx can only move along the five dimensions, no diagonals). Help Pirx search every room and find all the gold.
Input
First line: The size N of each dimension.
Second line: The constant C for terrain generation.
Output
First line: The total number of gold chests.
Second line: The number of rooms that contain at least one chest.
Third line: The largest number of gold chests in one room.
Constraints
3 ≤ N ≤ 20
2 ≤ C ≤ 10,000
Example
Input
```5
8```
Output
```1141
236
216```

Tags
Flood fill

Difficulty
Medium

Test cases
N=5 Test
Input
5 8
Output
1141 236 216

N=5 Validator
Input
5 23
Output
1382 74 651

N=10 Test
Input
10 77
Output
29552 3064 9090

N=10 Validator
Input
10 7777
Output
32251 3562 23325

N=15 Test
Input
15 11
Output
268939 1611 49408

N=15 Validator
Input
15 1111
Output
145380 38105 22030

N=20 Test
Input
20 9
Output
653072 143339 271

N=20 Validator
Input
20 99
Output
891383 137353 182225

Solution language

Solution

Stub generator input   Join the CodinGame community on Discord to chat about puzzle contributions, challenges, streams, blog articles - all that good stuff!
Online Participants