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 #68: Magic N-gon ring

Project Euler #68: Magic N-gon ring

Problem
Submissions
Leaderboard
Discussions

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

Consider the following "magic" ring, filled with the numbers to , and each line adding to nine.

img

Working clockwise, and starting from the group of three with the numerically lowest external node (4,3,2 in this example), each solution can be described uniquely. For example, the above solution can be described by the set: 4,3,2; 6,2,1; 5,1,3.

It is possible to complete the ring with four different totals: 9, 10, 11, and 12. There are eight solutions in total.

By concatenating each group it is possible to form 9-digit strings; the strings for a ring where total is are and .

Given , which represents the and the total print all concatenated solution strings in alphabetical sorted order.

Note: It is guaranteed that solution will exist for testcases.

Input Format

You are given and separated by a space.

Constraints

Output Format

Print the required strings each on a new line.

Sample Input

3 9

Sample Output

423531612
432621513

Author

shashank21j

Difficulty

Hard

Max Score

100

Submitted By

977

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