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

Prime Numbers II
- 19 Problems
- 7 Finishers
- List the delete-a-digit primes
- List the dihedral primes
- List the good primes
- Determine whether a number is a prime self number
- Compute home primes in a given base
- List Proth primes
- Label primes with the Erdos-Selfridge classification
- List Honaker primes
- List the nth prime quartet prefix
- Find the smallest prime with n inside
- List prime anagrams of a number
- Determine whether a number is unprimeable
- Count the primes in Collatz sequences
- Play Outside In with primes
- Identify prime words
- Find pairs of primes with the same digit sum and a specified separation
- List composite numbers that cannot be written as the sum of two primes
- Compute the arithmetic derivative of integers
- Solve the arithmetic differential equation D(n) = n
Problem Recent Solvers10
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!