Task. Consider the divisors of the number 30: 1, 2, 3, 5, 6, 10, 15, 30. You can see that for each divider d, the following holds: d + 30 / d is a prime number. For example, d = 2: 2 + 30/2 = 17 - simple

Find the sum of all natural numbers n not exceeding 100,000,000 such that for any divisor d of number n, the number d + n / d is prime. (i.e. the sum of such numbers that have properties like the number 30 from the example above)

Here is what I wrote:

function result($i, $num) { return $i + $num / $i; //Вычисляю } function isPrime($num) { if (gmp_prob_prime($num) == 2) //Проверяю, является ли простым return true; } $finish = 6; //Конечное число $data = []; $numbers = []; for ($NUMBER = 1; $NUMBER <= $finish; $NUMBER++) { for ($i = 1; $i <= $NUMBER; $i++) { $result = result($i, $NUMBER); if (is_integer($result) && isPrime($result)) { $data[] = $i; $numbers[] = $NUMBER; } } } foreach ($numbers as $num) { echo $num; } echo "<br>"; foreach ($data as $nums) { echo $nums; } 

In the case of 6, 1, 2, and 6 are suitable. We must exclude 4 and all similar numbers for which not all divisors are suitable for this condition.

    1 answer 1

     function result($i, $num) { return $i + $num / $i; //Вычисляю } function isPrime($num) { if (gmp_prob_prime($num) == 2) //Проверяю, является ли простым return true; } $finish = 6; //Конечное число for ($NUMBER = 1; $NUMBER <= $finish; $NUMBER++) { $is = true; for ($i = 1; $i <= $NUMBER; $i++) { $result = result($i, $NUMBER); if (is_integer($result)&&!isPrime($result)) { // это делитель и формула дала составное число? $is = false; break; // это не то, что нам нужно, дальше не ищем } } if($is) echo $NUMBER; // это то, что нам нужно } 

    In general, this is a parabola: -d ^ 2 + b * dx = 0 And if we find a solution for x from 1 to 100,000,000, where b is a composite number, then x does not suit us. Maybe someone more intelligent will offer a purely mathematical solution?