0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

力の除数

Last updated at Posted at 2019-07-15

#問題文
NK の正の約数であって、M 以下のものの個数を求めてください。

#ソース

<?php
//入力値
$nyu1 = 12; //値
$nyu2 = 3;  //累乗値
$nyu3 = 50; //M以下の値(上限値)

//算出対象値を求める(乗算)
$nyu = pow($nyu1,$nyu2);

//小数点以下を切り上げ
$limit = ceil($nyu);
//約数を求める
for($i=1; $i<=$limit; $i++){
    if($nyu%$i == 0){
        $array[] = $i;
    }
}

//M以下のものの値を求める
for($i=0; $i < count($array); $i++){
    if($array[$i] <= $nyu3){
        $answer[] = $array[$i];
    }
}
echo count($answer);
//var_dump($answer);
?>
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?