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 commentsProblem Recent Solvers10
Suggested Problems
-
6252 Solvers
-
4248 Solvers
-
477 Solvers
-
780 Solvers
-
105 Solvers
More from this Author279
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!