$n=<>; ($c,$v)=glob<>; printf sort{$a-$b}map{ $a=$f=0; ++$a while $a**$_<$n; ++$f while ($a-1)**($_-$f)*$a**$f<$n; $c*$_+$v*(($a-2)*$_+$f) }1..16