2017-05-05 12 views
1

だから、$ Aと$ B(間隔の枠を含む)のすべての平方数を求めたい。ここで出力され、これらの数の間の3つの平方数(整数)が存在するので、3であるべきである:4 = 2^2 = 3^2 9及び16 = 4^2PHPは間隔の平方数の量を見つける

function solution($A, $B) { 
    $A = 4; 
    $B = 17; 

    for($i=$A; $i<=$B; $i++) { 
    $sqrt = sqrt($i); 
    if (strpos($sqrt, '.') !== false) { 
     $sqrt = intval($sqrt); 
     print $sqrt; 
    } 
    } 
} 

答えて

0

チェックdemo here

range(ceil(sqrt($A)), floor(sqrt($B))); 
関連する問題