Problem 51241. Compute home primes in a given base
A home prime for a particular number is determined by factoring the number, concatenating the factors of the number (written in increasing order), and stopping when the resulting number is prime. The number 35149 is the home prime of 60 in base 10
2, 2, 3, 5 --> 2235 --> 35, 149 --> 35149
For a different base b, write the factors of the base-10 number in base b, concatenate the factors, and convert the result from base b to base 10. For example, the home prime of 60 in base 4 is 32183:
Factors in base 10 Factors in base 4 Base 4 number Base 10 number
2, 2, 3, 5 2, 2, 3, 11 22311 693
3, 3, 7, 11 3, 3, 13, 23 331323 3963
3, 1321 3, 110221 3110221 13609
31, 439 133, 1231 1331231 32183
Write a function that computes the home prime in the specified base. If the base is not specified, take it to be 10. If your code can pass the four optional tests (removed with comments in the test suite), please leave a note in the comments.
Solution Stats
Problem Comments
-
2 Comments
David Hill
on 27 Mar 2021
You could do those additional tests if the output were a character array by using Java BigInteger or Python.
Nikolaos Nikolaou
on 9 Apr 2023
Please correct that base 1 on your multiple bases case to 10
Solution Comments
Show commentsGroup

Easy Sequences Volume I
- 10 Problems
- 8 Finishers
- Easy Sequences 1: Find the index of an element
- Easy Sequences 2: Trigonometric function with integral input and output
- Easy Sequences 3: Prime 44-number Squares
- Easy Sequences 4: Eliminate the Days of Confusion
- Easy Sequences 5: Project Euler Problem 1 - Again!
- Easy Sequences 6: Coefficient sums of derivatives
- Easy Sequences 9: Faithful Pairs
- Easy Sequences 10: Sum of Cumsums of Fibonacci Sequence
- Easy Sequences 11: Factorial Digits without Trailing Zeros
- Easy Sequences 12: 50th Prime
Problem Recent Solvers10
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!