Home primes
In number theory, the home prime HP(n) of an integer n greater than 1 is the prime number obtained by repeatedly factoring the increasing concatenation of prime factors including repetitions.
This page uses content from Wikipedia. The original article was at Home prime. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) |
The traditional notation has the prefix "HP" and a postfix iteration count (if the count is greater than 0).
Prime numbers are their own Home prime;
So:
HP2 = 2 HP7 = 7
If the integer obtained by concatenating increasing prime factors is not prime, iterate with the iteration count until you reach a prime number; The Home prime.
HP4 = HP22(1) = 211 HP4 = 2 × 2 => 22; HP22(1) = 2 × 11 => 211; 211 is prime HP10 = HP25(1) = HP55(2) = HP511(3) = 773 HP10 = 2 × 5 => 25; HP25(1) = 5 × 5 => 55; HP55(2) = 5 × 11 => 511; HP511(3) = 7 × 73 => 773; 773 is prime
- Task
Find and show here, on this page, the Home prime iteration chains for the integers 2 through 20 inclusive.
- Stretch goal
Find and show the iteration chain for 65.
- Impossible goal
Show the the Home prime for HP49.
- See also
Raku
<lang perl6>use Prime::Factor;
for flat 2..20, 65 -> $m {
my ($n, @steps, @factors) = $m; @steps.push: $n = @factors.join.Int while (@factors = prime-factors($n)) > 1; my $s = 0; say "HP$m = ", (@steps[0..*-1]).map( { "{(++$s).fmt("HP$_\(%d)")}" } ).join(' = '), +@steps ?? " = {@steps.tail}" !! $m;
}</lang>
- Output:
HP2 = 2 HP3 = 3 HP4 = HP22(1) = HP211(2) = 211 HP5 = 5 HP6 = HP23(1) = 23 HP7 = 7 HP8 = HP222(1) = HP2337(2) = HP31941(3) = HP33371313(4) = HP311123771(5) = HP7149317941(6) = HP22931219729(7) = HP112084656339(8) = HP3347911118189(9) = HP11613496501723(10) = HP97130517917327(11) = HP531832651281459(12) = HP3331113965338635107(13) = 3331113965338635107 HP9 = HP33(1) = HP311(2) = 311 HP10 = HP25(1) = HP55(2) = HP511(3) = HP773(4) = 773 HP11 = 11 HP12 = HP223(1) = 223 HP13 = 13 HP14 = HP27(1) = HP333(2) = HP3337(3) = HP4771(4) = HP13367(5) = 13367 HP15 = HP35(1) = HP57(2) = HP319(3) = HP1129(4) = 1129 HP16 = HP2222(1) = HP211101(2) = HP3116397(3) = HP31636373(4) = 31636373 HP17 = 17 HP18 = HP233(1) = 233 HP19 = 19 HP20 = HP225(1) = HP3355(2) = HP51161(3) = HP114651(4) = HP3312739(5) = HP17194867(6) = HP194122073(7) = HP709273797(8) = HP39713717791(9) = HP113610337981(10) = HP733914786213(11) = HP3333723311815403(12) = HP131723655857429041(13) = HP772688237874641409(14) = HP3318308475676071413(15) = 3318308475676071413 HP65 = HP513(1) = HP33319(2) = HP1113233(3) = HP11101203(4) = HP332353629(5) = HP33152324247(6) = HP3337473732109(7) = HP111801316843763(8) = HP151740406071813(9) = HP31313548335458223(10) = HP3397179373752371411(11) = HP157116011350675311441(12) = HP331333391143947279384649(13) = HP11232040692636417517893491(14) = HP711175663983039633268945697(15) = HP292951656531350398312122544283(16) = HP2283450603791282934064985326977(17) = HP333297925330304453879367290955541(18) = HP1381321118321175157763339900357651(19) = 1381321118321175157763339900357651