# See if the current number raised to the given exponent is a factor of our base. If it is, the answer is n * i * exponent-root(the other factor)
my$newBase=$base/($count**$exp);
if(($newBase-int($newBase))==0){
return"The $exp-root of -$base is $count * i * the $exp-root of $newBase.",html=>"<sup>$exp</sup>√-$base = $count<em>i</em>⋅<sup>$exp</sup>√$newBase";
}
$count--;
}
# Can't be solved or simplified via the above methods
return"The $exp-root of -$base is i * the $exp-root of $base",html=>"<sup>$exp</sup>√-$base = <em>i</em>⋅<sup>$exp</sup>√$base";
# See if the current number raised to the given exponent is a factor of our base. If it is, we can give them a simplified version of the radical in addition to the answer.
my$newBase=$base/($count**$exp);
if(($newBase-int($newBase))==0){
return"The $exp-root of -$base is $calc (-$count times the $exp-root of $newBase).",html=>qq|<sup>$exp</sup>√-$base = <a href="javascript:;" onclick="document.x.q.value='$calc';document.x.q.focus();">$calc</a> (-$count⋅<sup>$exp</sup>√$newBase)|;
}
$count--;
}
return"The $exp-root of -$base is $calc.",html=>qq|<sup>$exp</sup>√-$base = <a href="javascript:;" onclick="document.x.q.value='$calc';document.x.q.focus();">$calc</a>|;
}
}
elsif($exp=~m/[0-9]+/){
# Solve normally
$base=str2nbr($base)if$base=~m/[^0-9]/;
$base=~s/[^0-9\.]//g;
if($basene''){
my$calc=$base**(1/$exp);
# Try and simplify the radical
my$count=int($calc);
while($count>1){
# See if the current number raised to the given exponent is a factor of our base. If it is, we can give them a simplified version of the radical in addition to the answer.
my$newBase=$base/($count**$exp);
if(($newBase-int($newBase))==0){
return"The $exp-root of $base is $calc ($count times the $exp-root of $newBase).",html=>qq|<sup>$exp</sup>√$base = <a href="javascript:;" onclick="document.x.q.value='$calc';document.x.q.focus();">$calc</a> ($count⋅<sup>$exp</sup>√$newBase)|;
}
$count--;
}
return"The $exp-root of $base is $calc.",html=>qq|<sup>$exp</sup>√$base = <a href="javascript:;" onclick="document.x.q.value='$calc';document.x.q.focus();">$calc</a>|;