We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • Hackerrank Home
  • Prepare
    NEW
  • Certify
  • Compete
  • Career Fair
  • Hiring developers?
  1. All Contests
  2. ProjectEuler+
  3. Project Euler #189: Tri-colouring a triangular grid

Project Euler #189: Tri-colouring a triangular grid

Problem
Submissions
Leaderboard
Discussions

This problem is a programming version of Problem 189 from projecteuler.net

Consider the following configuration of triangles:

We wish to colour the interior of each triangle with one of three colours: red, green or blue, so that no two neighbouring triangles have the same colour. Such a colouring shall be called valid. Here, two triangles are said to be neighbouring if they share an edge.
Note: if they only share a vertex, then they are not neighbours.

For example, here is a valid colouring of the above grid:

A colouring which is obtained from a colouring by rotation or reflection is considered from unless the two are identical.

Let's assume we have colours and triangles formed into above configuration. How many distinct valid colourings are there for such configuration?

Input Format

The only line of the test contains two integers: and .

Constraints



Output Format

Print exactly one integer which is the answer to the problem. Since that number could be very large, output it modulo .

Sample Input 0

1 3

Sample Output 0

3

Explanation 0

We can colour the only triangle in each of the three given colours.

Author

bayleef

Difficulty

Easy

Max Score

100

Submitted By

428

Need Help?


View discussions
View top submissions

rate this challenge

MORE DETAILS

Download problem statement
Download sample test cases
Suggest Edits
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy