寻找满足下列条件的4位整数:1.无重复数字;2.千位数字非0;3.能整除它的各位数字和的平方...

有待优化

function getInt()
{
    $intArray = [];
    for ($a=1; $a <= 9; $a++) { 
        for ($b=0; $b <= 9; $b++) { 
            if ($a != $b) {
                for ($c=0; $c <=9; $c++) { 
                    if ($c != $b) {
                        for ($d=0; $d <=9; $d++) { 
                            if ($d != $c) {
                                $sum = $a+$b+$c+$d;
                                $int = $a*1000 + $b*100 + $c*10 +$d;
                                if ($int%($sum*$sum) ==  0) {
                                    $intArray[] = $int;
                                } 
                            }
                        }
                    }
                }
                
            }
        }
        
    }

猜你喜欢

转载自blog.csdn.net/weixin_33851604/article/details/86992466