Magical primes

A magical prime is a number that is prime and has all its digits add up to a prime number. Assuming this, how many magical primes are there between 100-160?

0 7 6 5

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

3 solutions

Kyle T
Jul 26, 2019
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
$c = 0;
for($i=100;$i<=160;$i++){
    if(is_prime($i)){
        $v = array_sum(str_split($i));
        if(is_prime($v)){
            echo $i.' '.$v.'<br>';
            $c++;
        }
    }
}
echo 'total: '.$c;

function is_prime($n){ 
    if ($n == 1) 
    return false; 
    for ($i = 2; $i <= $n/2; $i++){ 
        if ($n % $i == 0) 
            return false; 
    } 
    return true; 
}

/*
101 2
113 5
131 5
137 11
139 13
151 7
157 13
total: 7
*/

?>

101, 113, 131, 137, 139, 151 and 157

Jonathan Tse
May 29, 2019

These are all the primes from 100-160:

101 103 107 109 113 127 131 137 139 149 151 157

Only 101, 113, 131, 137, 139, 151, 157 are magical primes.

So there are 7 magical primes from 100-160

These are apparently known as "additive primes". More info at OEIS here .

Chris Lewis - 2 years ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...