0 ;--$y){ $p = $X + $y*$y; if(isset($map[$p])){ $map[$p]++; }else{ $map[$p] = 1; } } } $count = 0; for($z = 1; $z <= $n; ++$z){ $Z = $z*$z - $d; for($w = $n; $w > 0; --$w){ $p = $w*$w - $Z; if(isset($map[$p])){ $count+=$map[$p]; } } } echo $count;