• 12

Learning Opportunities

This puzzle can be solved using the following concepts. Practice using these concepts and improve your skills.

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

A higher resolution is required to access the IDE

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