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 #74: Digit factorial chains

Project Euler #74: Digit factorial chains

Problem
Submissions
Leaderboard
Discussions

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

The number is well known for the property that the sum of the factorial of its digits is equal to :

Perhaps less well known is 169, in that it produces the longest chain of numbers that link back to 169; it turns out that there are only three such loops that exist:

It is not difficult to prove that EVERY starting number will eventually get stuck in a loop. For example,

Starting with produces a chain of five non-repeating terms, but the longest non-repeating chain with a starting number below one million is sixty terms.

For a given length and limit print all the integers which have chain length

Input Format

First line contains , followed by lines.
Each line contains and separated by space.

Constraints



Output Format

Print the integers separated by space for each testcase. Where there are no such number for a given , print -1.

Sample Input

10
221 7
147 1
258 4
265 8
210 2
175 7
29 2
24 3
273 4
261 4

Sample Output

24 42 104 114 140 141
1 2 145
78 87 196 236
4 27 39 72 93 107 117 170 171
0 10 11 154
24 42 104 114 140 141
0 10 11
-1
78 87 196 236 263
78 87 196 236

Author

shashank21j

Difficulty

Easy

Max Score

100

Submitted By

1433

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