<?php
$save_factorial=array();
function factorial($n)
{
global $save_factorial;
if($n==1||$n==0)
return 1;
if(isset($save_factorial[$n]))
return $save_factorial[$n];
$save_factorial[$n]=bcmul($n,factorial($n-1));
return $save_factorial[$n];
}
$t=trim(fgets(STDIN));
for($k=1;$k<=$t;$k++)
{
$i=trim(fgets(STDIN));
echo factorial($i)."\n";
}
?>
Friday, 10 August 2018
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment