Desmos, 61 10+38=48 bytes
l=log_m(n)
\sum_{m=2}^{n-1}(sign(l-ceil(l))+1)l^m
View it online (note that large values may fail because Desmos doesn't handle large numbers well)
I decided to revisit this because I felt like outgolfing myself, and I remember this having potential inefficiencies. I could only find one improvement, but it seemed substantial enough for the edit.
Input is via the variable n
, output via the second calculation. If taking input via a variable feels wrong, feel free to add two bytes for a n=
.
Not horribly efficiently golfed. About 70% of the code is just dedicated to finding one factor, and there's surely a more efficient way to factor numbers in Desmos, but I haven't found one yet, and Desmos is lacking in built-ins relating to factorization or prime numbers.
Instead, we simply observe that since \$p\$ and \$q\$ are prime, then \$p*p...*p\$ must be the only factorization of \$n\$ which can be represented with integer values, because the list of \$p\$s cannot be split into any other even groups. Therefore, we can just interate through all integers \$m \in 2,3,...,n-1\$ and find the value satisfying \$log_mn \in \mathbb{Z}\$ (the set of integers). We do this in the code using sign(log_m(n)-ceil(log_m(n)))+1
, which gives us a nice 1 when integeral and 0 when not. We multiply by log_m(n)^m
to give us our new value, and add up the results for all values 2 through n-1 to single out the answer.
q
is a prime does not seem to matter. \$\endgroup\$