14
Inspired by digital roots, the prime factoral root of a number is the number that emerges when you take the prime factors of a number, add them together, and repeat the process on the resulting number, continuing until you end up with a prime number (which has itself as its only prime factor, and is thus its own prime factoral root). The prime factoral root of 4 is 4, as 2*2=2+2, and this is the only non-prime prime factoral root of an integer greater than 1 (which is another special case, as it has no prime factors). The OEIS sequence formed by prime factoral roots is A029908.
For example, the prime factoral root of 24 is:
24=2*2*2*3
2+2+2+3=9=3*3
3+3=6=2*3
2+3=5, and the only prime factor of 5 is 5. Therefore, the prime factoral root of 24 is 5.
Your Task:
Write a program or function that finds the prime factoral root of an input integer.
Input:
An integer, input through any reasonable method, between 2 and the largest integer your language will support (inclusive). Specifically choosing a language that has an unreasonably low maximum integer size is not allowed (and also violates this standard loophole)
Output:
An integer, the prime factoral root of the input.
Test Cases:
4 -> 4
24 -> 5
11 -> 11
250 -> 17
Scoring:
This is code-golf, lowest score in bytes wins!
3Can you add
4
in the test cases, since it's an exception and it's easy to forget about it while testing an answer? – scottinet – 2017-10-04T11:26:20.713Do we have to output 1 for 1? – my pronoun is monicareinstate – 2017-10-04T11:36:16.103
@someone according to the linked OEIS sequence, it should output 0 for 1 – scottinet – 2017-10-04T11:55:02.960
2@someone The challenge states that the input will be at least 2. – Martin Ender – 2017-10-04T13:21:01.463
@someone Sorry for being off for a while. As Martin said, the challenge specifically says that the input will be greater than one, and therefore behavior when the input is 1 is undefined. – Gryphon – 2017-10-05T01:18:15.687
The name of this challenge seems like someone just took a bunch of random math terms and shoved them together. – Esolanging Fruit – 2017-10-06T07:17:05.903
I know. It makes sense when you read the question, but not really before that. – Gryphon – 2017-10-06T10:39:13.053