Last active
September 19, 2019 15:15
-
-
Save bz0/2d58dad97703f888b4536f2832767498 to your computer and use it in GitHub Desktop.
【試し中】Divisors of Power:https://yukicoder.me/problems/no/847
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//素因数分解 試し割法 | |
function p_factor($num){ | |
$factor = []; | |
$max = ceil(sqrt($num))+1; //√n+1 誤差のおそれがあるので+1する | |
for($i=2; $i<=$max; $i++){ | |
while($num % $i == 0){ //約数判定 | |
$num = $num / $i; | |
$factor[$i] = isset($factor[$i]) ? $factor[$i] + 1 : 1; | |
} | |
} | |
if (!$factor){ | |
$factor[$num] = 1; | |
return $factor; | |
} | |
if ($num > 1){ | |
$factor[$num] = isset($factor[$num]) ? $factor[$num]++: 1; | |
} | |
return $factor; | |
} | |
$args = explode(" ", trim(fgets(STDIN)));//入力データを取得 | |
$num = $args[0]; | |
$factor = p_factor($num); | |
print_r($factor); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//約数を全部出力する | |
//数値が大きくなるとInfiniteとなり処理できなくなる・処理が長くタイムアウトする | |
$args = explode(" ", trim(fgets(STDIN))); | |
$N = $args[0]; | |
$K = $args[1]; | |
$M = $args[2]; | |
$num = pow($N, $K); | |
$max = min($M, $num); | |
$divisor = []; | |
for($i=1;$i<=$max;$i++){ | |
if($num%$i==0 && $M>$i){ | |
$divisor[] = $num; | |
} | |
} | |
$count = count($divisor); | |
echo $count; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment