-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path27.php
58 lines (40 loc) · 1.05 KB
/
27.php
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
function getSum($num){//получить сумму делителей числа $num
$tempNum = 0;
for($i = 1; $i <= $num; $i++){
$res = $num / $i;
if(gettype($res) == "integer" && testPrimal($i)) {
$tempNum += $i;
}
}
return $tempNum;
}
function testMaxSum($currentSum, &$maxSum, &$tempNum, $currentNum){
if($maxSum < $currentSum) {
$maxSum = $currentSum;
$tempNum = $currentNum;
}
}
function testPrimal($N){
$fl = true;
for($n = 2; $n <= $N / 2; $n++) {
$res = $N / $n;
if( gettype($res) == "integer"){
$fl = false;
break;
}
}
return $fl;
}
$n1 = 25;//ряд чисел
$n2 = 29;
$n3 = 11;
$maxSum = 0;
$tempNum;
$x = getSum($n1);
testMaxSum($x, $maxSum, $tempNum, $n1);
$x = getSum($n2);
testMaxSum($x, $maxSum, $tempNum, $n2);
$x = getSum($n3);
testMaxSum($x, $maxSum, $tempNum, $n3);
echo "Максимальная сумма простых делителей - ", $maxSum, ", у числа - ", $tempNum;