13 private static function factors(
float $value): array
15 $startVal = floor(sqrt($value));
18 for (
$i = $startVal;
$i > 1; --
$i) {
19 if (($value %
$i) == 0) {
20 $factorArray = array_merge($factorArray, self::factors($value / $i));
21 $factorArray = array_merge($factorArray, self::factors($i));
22 if ($i <= sqrt($value)) {
27 if (!empty($factorArray)) {
33 return [(int) $value];
58 $anyNonNulls += (int) ($value1 !== null);
61 $arrayArgs[] = (int) $value;
62 $anyZeros += (int) !((
bool) $value);
64 self::testNonNulls($anyNonNulls);
69 return $e->getMessage();
73 $allPoweredFactors = [];
75 foreach ($arrayArgs as $value) {
76 $myFactors = self::factors(floor($value));
77 $myCountedFactors = array_count_values($myFactors);
78 $myPoweredFactors = [];
79 foreach ($myCountedFactors as $myCountedFactor => $myCountedPower) {
80 $myPoweredFactors[$myCountedFactor] = $myCountedFactor ** $myCountedPower;
82 self::processPoweredFactors($allPoweredFactors, $myPoweredFactors);
84 foreach ($allPoweredFactors as $allPoweredFactor) {
85 $returnValue *= (int) $allPoweredFactor;
93 foreach ($myPoweredFactors as $myPoweredValue => $myPoweredFactor) {
94 if (isset($allPoweredFactors[$myPoweredValue])) {
95 if ($allPoweredFactors[$myPoweredValue] < $myPoweredFactor) {
96 $allPoweredFactors[$myPoweredValue] = $myPoweredFactor;
99 $allPoweredFactors[$myPoweredValue] = $myPoweredFactor;
static validateNumericNullSubstitution($number, $substitute)
Validate numeric, but allow substitute for null.
static flattenArray($array)
Convert a multi-dimensional array to a simple 1-dimensional array.
static evaluate(... $args)
LCM.
static testNonNulls(int $anyNonNulls)
static processPoweredFactors(array &$allPoweredFactors, array &$myPoweredFactors)
static factors(float $value)
static validateNotNegative($number, ?string $except=null)
Confirm number >= 0.