[Question]
  [
**Input:**
A positive integer `n=p^q` where `p` and `q` are [prime](https://www.mathopenref.com/prime-number.html).
**Output:**
Output the result of `q^p`
**Test cases (in, out):**
```
4, 4
8, 9
25, 32
27, 27
49, 128
121, 2048
125, 243
343, 2187
1331, 177147
3125, 3125, 
16807, 78125, 
823543, 823543
161051, 48828125
19487171, 1977326743
```
**Scoring:**  
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so may the shortest code in bytes win! Input and output maybe in any reasonable format suitable to your language.
Related:  
[Recover the power from the prime power](https://codegolf.stackexchange.com/questions/167199/recover-the-power-from-the-prime-power)  
[Recover the prime from the prime power](https://codegolf.stackexchange.com/questions/167106/recover-the-prime-from-the-prime-power)
  
[Answer]
# [Python 2](https://docs.python.org/2/), 56 bytes
```
n=input()
p=2
while n%p:p+=1
P=p**n-1
print(n**n/P%P)**p
```
[Try it online!](https://tio.run/##JYtbCoMwEEX/ZxVBEDSl1MmjiUJ@ugK3UCTUQI1DHWm7eqv04144HA59eZyz2t5jekaBXfzEoSiKLYeUaeWqBgoK/jaX1NEpIPSBpMxnBHqlzFXe4dKXfS0lbUdswIOyoByYFlDhPgvaaECtEfRBePWN2x8bi1Dd0kNwXFgM9yUugtMUxbxyDV5pe3St8Q4d/gA "Python 2 – Try It Online")
We first find the prime \$p\$ for which \$n=p^q\$ by incrementing \$p\$ until we get a divisor on \$n\$. After that, we find the exponent \$q\$ with a mathematical trick first discovered by Sp3000 and used in [Perfect power logarithms](http://golf.shinh.org/p.rb?Perfect%20power%20logarithms) on Anarchy Golf.
We note that
$$ \frac{n-1}{p-1} = \frac{p^q-1}{p-1} = 1 + p + p^2 \dots+p^{q-2}+p^{q-1}$$
Working modulo \$p-1\$, we have \$p \equiv 1\$, so each of \$q\$ the summands on the right hand side equals 1, and so:
$$ \frac{n-1}{p-1} \equiv q \space \bmod (p-1)$$
We'd now like to extract \$q\$. We'd like to get there by applying the modulus operator `%(p-1)` to the left hand side. But this requires that \$q<p-1\$, which is not guaranteed, or we'll get a different value of `q%(p-1)`.
Fortunately, we can get around this with one more trick. We can replace \$n\$ with \$n^c\$ and \$p\$ with \$p^c\$ for some positive number \$c\$, and still have \$n^c=(p^c)^q\$. Since the exponent \$q\$ relating them is unchanged, we can extract it as above, but make it so that \$q<p^c-1\$. For this, \$c=n\$ more than suffices and is short for golfing, though it makes larger test cases time out.
[Answer]
# [Bash](https://www.gnu.org/software/bash/) + Linux utils, 17
```
factor|dc -e?zr^p
```
* `factor` takes a number as input and factorizes it. The output is the input number, followed by a colon, followed by a spaced-separated list of all the prime factors.
* This list is piped to `dc` which evaluates the following `e`xpression:
	+ `?` reads the whole line as input. dc cannot parse the input number followed by the colon, so it ignores it. Then it parses all the space-separated prime factors and pushes them to the stack.
	+ `z` takes the number of items on the stack (number of prime factors) and pushes that to the stack
	+ `r` reverses the top two items on the stack
	+ `^` exponentiates, giving the required answer
	+ `p` prints it.
[Try it online!](https://tio.run/##FYoxC8IwFAb371e8wVXoy0uaFAenbg7iJogQk0gEMZIKgvS/x3a44Y67@Sm3b348E9Xk445iQQq50OY0Hg9nmunS7j58Sp1joG3a/@r13WJ5pabhoAyUhR7AihcMRAtYhCGrce86C6fErLnnzizXoJ1ly/gD "Bash – Try It Online")
[Answer]
# [MATL](https://github.com/lmendo/MATL), ~~8~~ 5 bytes
-3 bytes thanks to @LuisMendo
```
&YFw^
```
[Try it online!](https://tio.run/##y00syfn/Xy3SrTzu/38LAA "MATL – Try It Online")
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 5 bytes
```
ÓOsfm
```
[Try it online!](https://tio.run/##yy9OTMpM/f//8GT/4rTc//@NTAE "05AB1E – Try It Online")
**Commented:**
```
        # implicit input            25
Ó       # prime factor exponents    [0, 0, 2]
 O      # sum                       2
  s     # swap (with input)         25, 2
   f    # unique prime factors      [5], 2
    m   # power                     [32]
```
[Answer]
# [J](http://jsoftware.com/), 9 8 bytes
```
2^~/@p:]
```
[Try it online!](https://tio.run/##VY69CsJAEIT7PMViEwMasz/J7gUCgmBlZa@NGMRGn8BXP3MXuYvFcjsfM7P39Ku6HGHooYQNNNBPs63hcD4dPV0/u/27v/iqKO63xwvWI0gFA0iSFqRLktqgmTLQAEhz3gWAZIkgYfQ0smSxiIQTYuGI0HIZMscsqqJkzL94eLO3syZ@Rm2Jjbidm@dt4cemje1iRn8ZdGKKOp92qkydTkn/BQ "J – Try It Online")
* `2 p: ]` returns a list of primes and their exponents.
* `^~/@` then swap the arguments and exponentiate
[Answer]
# [Python 2](https://docs.python.org/2/), 62 bytes
```
n=input()
p=2
q=-1
while n%p:p+=1
while n:n/=p;q+=1
print q**p
```
[Try it online!](https://tio.run/##K6gsycjPM/r/P882M6@gtERDk6vA1oir0FbXkKs8IzMnVSFPtcCqQNsWzrXK07ctsC4EiRQUZeaVKBRqaRX8/29oZmhgaggA "Python 2 – Try It Online")
[Answer]
# [C (gcc)](https://gcc.gnu.org/) `-lm`, 47 bytes
```
p;f(n){for(p=1;n%++p;);p=pow(log(n)/log(p),p);}
```
[Try it online!](https://tio.run/##dVLtaoMwFP3fp7gUCmojNh9tIln3Z@wp1jI6q05wMVRhsuKrz92ktttgE3JvPOd@nJski8ssG0eri8CE56I5BXZLtVksl1aH2m5t8x7UTYlk4pwNiQ31MFamg7dDZYJwdp4Bfg7o8rZ7Nk972CJwFgQUAbbGJQmIlABQRr1FjAvutpw7BLjH6EatMFQxvnYs3dDVmg4a@SSCrmmgbkwJqBE4i1@qzjclNBVKUukDo@QmJu9t3nf50ctxYlAAZxcxlDllK@Gs68SocqiUVKC/iJHKu6sYoRRzCHb5XwzWSKXkbCMFH3SUgFeTvR5OEZwuQua7/pHt@vQB13pO4Oc/nw965lNc2cBNUZlj3mPeSk/bO2irj7wpgut8YTIB0Q3RsFz66BAul3M9E4OVpkvy/F7/onOkb8f2V0CLAe6dfKP2hHgRzBdHiO8B7aLdGRzLEGgJzowlt9Dup4xhNoyfWVEfynaM67cv "C (gcc) – Try It Online")
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), 6 bytes
```
ḋ⟨l^h⟩
```
[Try it online!](https://tio.run/##SypKTM6ozMlPN/pfXa6koGunoFRu/6htw6OmpofbFjzc1Vn7cOuE/w93dD@avyInLuPR/JX//0eb6ChY6CgYmQKxuY6CiaWOgqGRIYgAihibGANZxsZAvjFYwNDMwgCoysLI2BQsZWZoYApSbGliYW5obhj7PwoA "Brachylog – Try It Online") On the prime decomposition `ḋ` (like `[5, 5]`), length `l` `^` first element `h`.
A nicer and more Brachylog-y solution, that is one byte longer:
```
 ~^ṗᵐ↔≜^
```
[Try it online!](https://tio.run/##SypKTM6ozMlPN/pfXa6koGunoFRu/6htw6OmpofbFjzc1Vn7cOuE/3VxD3dOBzIetU151Dkn7v//aBMdBQsdBSNTIDbXUTCx1FEwNDIEEUARYxNjIMvYGMg3BgsYmlkYAFVZGBmbgqXMDA1MQYotTSzMDc0NY/9HAQA) Reverse `~^` to get two Numbers `[A,B]` so that `Input = A^B`, while both are prime `ṗᵐ`. Flip `↔` the list to `[B,A]`, actually find the numbers `≜` and output `B^A`.
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 6 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
```
k
ÊpUg
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&code=awrKcFVn&input=MTMzMQ)
```
k\nÊpUg     :Implicit input of integer U
k           :Prime factors
 \n         :Reassign to U
   Ê        :Length
    p       :Raised to the power of
     Ug     :First element of U
```
[Answer]
# [R](https://www.r-project.org/), 37 bytes
```
log(n<-scan(),p<-(b=2:n)[!n%%b][1])^p
```
[Try it online!](https://tio.run/##K/r/Pyc/XSPPRrc4OTFPQ1OnwEZXI8nWyCpPM1oxT1U1KTbaMFYzruC/oZHhfwA "R – Try It Online")
My best effort, sadly 1-byte longer than the [Xi'an's much-cleverer R answer](https://codegolf.stackexchange.com/questions/210437/prime-power-switch/210466#210466), but posting anyway in the competitive spirit.
Uses the straightforward approach of finding the prime factor (`p<-(b=2:n)[!n%%b][1]`), then the exponent (`log(n,p)`) and finally raising the exponent to the power of the factor (`log(n,p)^p`).
[Answer]
# JavaScript (ES7), ~~47 46~~ 44 bytes
Uses a recursive function that first looks for the smallest divisor \$k\ge2\$ of \$n\$ and then counts how many times \$n\$ can be divided by \$k\$. The result is raised to the power of \$k\$.
```
n=>(k=2,g=_=>n%k?n>1&&g(k++):1+g(n/=k))()**k
```
[Try it online!](https://tio.run/##bZHLbsIwEEX3fEU2IJsUknmEmVRy@BSEKETUyEGA@vtpUSJknHo3OsfXd@Tv/c/@fridr49V6L6O/cn1wTXGO/xo3c41Ye63oYHFojU@z@0n5K0JhfPWGrtc@v7QhXt3Oa4vXWtOhrPhWJsVRcazd6pvtE4oVjElTLHEGCXBXMcYUBMOCPH1kqdCFQtMCSemmIOmDYAIogYiwKlC4yPjin9TmrHRUl6C6NRQpOrZZDCGaRICZQWvT1DFf3KgZhUQGNvWIoQbYep/AQ "JavaScript (Node.js) – Try It Online")
### Commented
```
n => (          // main function taking n
  k = 2,        // start with k = 2
  g = _ =>      // g is a recursive function ignoring its input
    n % k ?     //   if k is not a divisor of n:
                //     this point of the code is reached during the first step
                //     of the algorithm; but it's also reached on the last
                //     iteration when n = 1, which is why ...
      n > 1 &&  //     ... we test whether n is greater than 1 ...
        g(k++)  //       ... in which case we do a recursive call with k + 1
    :           // else (k has been found):
      1 +       //   add 1 to the final result
      g(n /= k) //   and do a recursive call with n / k
)()             // initial call to g
** k            // raise the result to the power of k
```
[Answer]
# [R](http://cran.r-project.org) ~~36~~ ~~28~~ ~~1~~ 36 bytes
Using the fact that exactly `p` powers of `n` are factors of `n^p`:
```
sum(a<-!max(b<-2:scan())%%b)^b[a][1]
```
[Try it online!](https://tio.run/##K/r/v7g0VyPRRlcxN7FCI8lG18iqODkxT0NTU1U1STMuKToxNtow9r/FfwA "R – Try It Online")
but using a function definition does better (by moving `function(m)` to the header part!)
```
f=function(m)
sum(a<-!m%%(b<-2:m))^b[a][1]
```
[Try it online!](https://tio.run/##K/qfZptWmpdckpmfp5Gr@b@4NFcj0UZXMVdVVSPJRtfIKldTMy4pOjE22jD2f5pGmoZJnLGmJheIZQ5i/QcA "R – Try It Online")
with the ultimate improvement in length (1 byte!) produced by defining everything as the function argument (in the header of Try It Online).
```
f=function(m,b=2:m,a=!m%%b,d=sum(a)^b[a][1]) d
```
but this is not keeping with the code golf spirit!
[Answer]
# [Haskell](https://www.haskell.org/), ~~42~~, 39 bytes
```
f x|r<-[2..x]=[z^w|z<-r,w<-r,w^z==x]!!0
```
[Try it online!](https://tio.run/##PZBfC4IwFMXf@xQniFCY4f7UJrhe@hhm4INRZBIqOKXvbtcmvtz9zt2557I9ivZVVtXUlW13KdqyhUUWKAYVsg0QGIbEkzgySLGwZhDas0oYuDBecMHpJlarpCGhpFdSSVLcLINcSjJzrblaOvLvn@viOJmYNmmzdoyQxznFn2E@3eG@TRpl4nBwuc3GW/8d06hh/b/cRmtdvt3G07t41vS0T/OsO@woqqgqBNfAMQwhojMoCNZiwH5PPMzsQqzfMv0A "Haskell – Try It Online")
* 3 bytes saved by @xnor
[Answer]
# [Ruby](https://www.ruby-lang.org/), 56 bytes
```
n=gets.to_i
p=2
p+=1while n%p>0
w=p**n-1
p (n**n/w%w)**p
```
Port of xnor's Python 3 answer.
[Try it online!](https://tio.run/##JY3NDoIwEITv@xR7IdEaleXH9kC9qGcfwfCzUSIpTQEbn76CXCbfTGYybqq@oe4bRo1Fcblfb8HoJ4/DYewfLVidgN1p8q@2YzSRPcfgtRXC7AksbsxMRx/5rRA2LGuAtTq6ibHpAZE/ZYf/B8dDPaeV4/INbJpAaUpAUlImIaUkX4VOKpYg1coU5wSZUsnifw) (headers and footers courtesy of ovs. :D)
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), 5 bytes
```
ǐ₌Lhe
```
[Try it Online!](https://vyxal.pythonanywhere.com/#WyIiLCLGmyIsIseQ4oKMTGhlIiwiO1rGm2AgPT4gYGo74oGLIiwiWzQsIDgsIDI1LCAyNywgNDksIDEyMSwgMTI1LCAzNDMsIDEzMzEsIDMxMjUsIDE2ODA3LCA4MjM1NDMsIDE2MTA1MSwgMTk0ODcxNzFdIl0=)
## How?
```
ǐ₌Lhe
ǐ     # Prime factors with duplicates
 ₌    # Apply both of next two elements and push both results to the stack:
  L   #  Length
   h  #  First item
    e # Exponentiate these two (length ^ first item)
```
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 24 bytes
```
#2^#&@@@FactorInteger@#&
```
[Try it online!](https://tio.run/##FYqxCsIwEED3/kYg0wm9XNKkg3KT4CY4isIRUu3QCCGb2F@P7fCG93iL1HdapM5R2nRsyjyVZuazxPopl1zTKxVWul3LnOtdHU4Tq4deb1Hy@u0sBDAOjAc7AhrccECWAIkQaDccQu8hGHJ7HrB32zXa4NFj92t/ "Wolfram Language (Mathematica) – Try It Online")
Returns `{q^p}`, a singleton list.
```
        FactorInteger@# (* {{p,q}} *)
#2^#&@@@                (* { q^p } *)
```
[Answer]
# [Retina](https://github.com/m-ender/retina/wiki/The-Language), 59 bytes
```
.+
*
~`(?=(__+?)\1*$)((?=(_+)(\3+)$)\4)+
_+¶$$.($.1*$($#2$*
```
[Try it online!](https://tio.run/##K0otycxLNPyvquGe8F9Pm0uLqy5Bw95WIz5e214zxlBLRVMDzNXW1Igx1tZU0Ywx0dTmitc@tE1FRU9DRQ@oQkNF2UhF6/9/Ey4LLiNTLiNzLhNLLkMjQyA25TI2MeYyNDY25DIG8QzNLAzMAQ "Retina – Try It Online") Link includes faster test cases. Explanation:
```
.+
*
```
Convert the input to unary.
```
(?=(__+?)\1*$)((?=(_+)(\3+)$)\4)+
```
First, find the smallest nontrivial factor, which will necessarily be `p`. Secondly, count the number of times `q` that `n` can be replaced with its largest proper factor. (The proper factor will be `n/p` on the first pass and eventually decrease to `1` which is left unmatched but this doesn't affect the result.)
```
_+¶$$.($.1*$($#2$*
```
Generate a Retina stage which takes `n` as input and calculates (in decimal) the result of multiplying `1` by `q` `p` times, thus calculating `q^p`.
```
~`
```
Evaluate the resulting code, thus calculating the desired result.
[Answer]
# [Scala](http://www.scala-lang.org/), 63 bytes
```
n=>2 to n find(n%_<1)map{p=>import math._;pow(log(n)/log(p),p)}
```
[Try it online!](https://tio.run/##NVHbasMwDH33VwjTQQxeVl9aO9sSKOxlD2MfsI3ipm6bkdom8W6Ufntnt5sM1pF1jrCksTW9OfnVu20jPJnOgf2O1q1HWIQAB/RpetjcwqOLUDfwHGLn3cuD/1j19g3qk6sbDtGDg03n1oW7Wt4zsjfhEOqm2wc/RNibuCuXd8F/Fb3fFo7cZBcIDeR4whhLChJpChXiMwqCI64ocIVkRYFxjRhnKZ7KjBKBS4GEFAkwrRATImWZUkwqJM6EfCM219NURukcaC5mWXHxKcems6SSWvNznlVSK6ZyoUopwedKivSxcgx9Fwv86jApc09j3SCA8f@dAia5u3aX5gTJWjNaWAyD@SkcHciZnS3PcLAj1LApXBl9GiYptzZe4B8pDJ2LvStGPHFw3cAkKWhaRkiLset6MmCSmEeUzukX "Scala – Try It Online")
Finds the first factor of `n`, which must be `p` because `n` is a prime power, then finds \$\log\_p(n)^p\$. Returns an `Option[Double]` that's a `Some[Double]` if the input is valid.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 6 bytes
```
ÆFẎṪ*$
```
[Try it online!](https://tio.run/##y0rNyan8//9wm9vDXX0Pd67SUvl/uP1R05rI//9NdBQsdBSMTIHYXEfBxFJHwdDIEEQARYxNjIEsY2Mg3xgsYGhmYQBUZWFkbAqWMjM0MAUptjSxMDc0NwQA "Jelly – Try It Online")
# [Jelly](https://github.com/DennisMitchell/jelly), 6 bytes
```
ÆFẎ*@Ɲ
```
[Try it online!](https://tio.run/##y0rNyan8//9wm9vDXX1aDsfm/j/c/qhpTeT//yY6ChY6CkamQGyuo2BiqaNgaGQIIoAixibGQJaxMZBvDBYwNLMwAKqyMDI2BUuZGRqYghRbmliYG5obAgA "Jelly – Try It Online")
# [Jelly](https://github.com/DennisMitchell/jelly), 6 bytes
```
ÆfL*ḢƊ
```
[Try it online!](https://tio.run/##y0rNyan8//9wW5qP1sMdi451/T/c/qhpTeT//yY6ChY6CkamQGyuo2BiqaNgaGQIIoAixibGQJaxMZBvDBYwNLMwAKqyMDI2BUuZGRqYghRbmliYG5obAgA "Jelly – Try It Online")
A 5-byter feels possible...
[Answer]
# [J](http://jsoftware.com/), 8 bytes
```
2^~/@p:]
```
[Try it online!](https://tio.run/##y/qvpKegnqZga6WgrqNgoGAFxLp6Cs5BPm7/jeLq9B0KrGL/K/g56SlwRVsB@UZqBVZcEL5hnL5DjR6SQI2emp4GiK8JFdCo1lNW1lTTK0RREW@oVghUovk/TcHQyJQLSFqaWJgbmhtWAAA "J – Try It Online")
J has a built-in that gives the prime factorization of a given integer in prime-exponent form. Then it's just a matter of applying exponentiation in reverse (`^~`) between the two numbers.
(Happens to be the same as [Jonah's answer](https://codegolf.stackexchange.com/a/210439/91267); somehow didn't notice before I submitted the answer...)
---
Because it is also solvable using `f&.g` ("Under"; do action g, do action f, then undo action g), here are some interesting ones:
### 10 bytes
```
|.&.(2&p:)
     2&p:  Prime factorization into prime-exponent form
|.         Swap the prime and exponent
  &.       Undo `2&p:`; evaluate the "prime" raised to "exponent"
```
[Try it online!](https://tio.run/##y/qvpKegnqZga6WgrqNgoGAFxLp6Cs5BPm7/a/TU9DSM1AqsNP8r@DnpKXBFW8XV6YMEuCB8wzh9hxo9JAGEDqiARrWesrKmml4hiop4Q7VCoBLN/2kKhkamXEDS0sTC3NDcsAIA "J – Try It Online")
### 10 bytes
```
({.##)&.q:
        q:  Prime factorization into plain list of primes
 {.         Head (prime)
   #        Copies of
    #       Length (exponent)
 {.##       Essentially swap the role of prime and exponent
      &.    Undo `q:`; product of all "primes"
```
[Try it online!](https://tio.run/##y/qvpKegnqZga6WgrqNgoGAFxLp6Cs5BPm7/Nar1lJU11fQKrf4r@DnpKXBFW8XV6RupFVhxQfiGcfoONXpIAjV6anoaIL4mVABhBLKKeEO1QqASzf9pCoZGplxA0tLEwtzQ3LACAA "J – Try It Online")
[Answer]
# [Alice](https://github.com/m-ender/alice), 13 bytes
```
/ \f~#oE/
 i@
```
[Try it online!](https://tio.run/##S8zJTE79/19fISatTjnfVZ9LIdPh/38jUzMA)
**Explanation:**
```
/           Switch to Ordinal mode
 i          Push the input as a string
  \         Switch to Cardinal mode
   f        Pop n, implicitly convert n to an integer, 
            and push the prime factors of n as pairs of prime and exponent
    ~       Swap the top two elements of the stack
     #      Skip the next command
       E    Pop y, pop x. If y is non-negative, push x ^ y
        /   Switch to Ordinal mode
      o     Pop s, then output s as a string.
    ~       Swap the top two elements of the stack.
  \         Switch to Cardinal mode
  @         Terminate the program
```
[Answer]
# [Forth (gforth)](http://www.complang.tuwien.ac.at/forth/gforth/Docs-html/), 85 bytes
```
: f dup 2 do dup i mod 0= if i leave then loop tuck swap s>f fln s>f fln f/ s>f f** ;
```
[Try it online!](https://tio.run/##RczNDkQwGIXhvas4awmjMkllhHsR7YcoX0Nx@fUXY/U@Z3OIJ9dGDZ3x/geCWixSKL7QYWCFpEBHh42uVg3X6hGG2cItdY95qyzmkkBm/Jc@N8MQuc@OV4pRT4FIxWspxVc@0@8 "Forth (gforth) – Try It Online")
Works like [Noodle9's C answer](https://codegolf.stackexchange.com/a/210455/78410). Takes an integer and returns a floating-point number on the FP stack.
### How it works
```
: f ( n -- float )
  dup 2 do           \ loop from i = 2..n-1
    dup i mod 0= if  \ if n % i == 0
      i leave        \ ( n p ) we found p; leave the loop
    then             \ end if
  loop               \ end loop
  tuck swap          \ ( p p n )
  s>f fln s>f fln    \ ( p F:ln(n) F:ln(p) )
  f/                 \ ( p F:q ) q = ln(n)/ln(p)
  s>f f**            \ ( F:q**p )
;
```
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), ~~7~~ 6 bytes
-1 byte thanks to @FryAmTheEggman
```
^lPQhP
```
[Try it online!](https://tio.run/##FYo7DoAgEAX7dwx6DcvyvYA1XMDKAhMjJtp4eVcoppjJXO9TZSlzkfXIpWYRpWARYRxMgE0gQx0HtgxiJvAw8lEHRMNuZE/a9SvZGCjQ165nb@ct0/YD "Pyth – Try It Online")
## Explanation
```
^lPQhP
 l      # length of
  PQ    # prime factors of input
^       # raised to power of
    hP  # first element in prime factors of input
```
[Answer]
# [Io](http://iolanguage.org/), ~~57~~ 55 bytes
Fixed a bug kindly pointed out by @DominicvanEssen
```
method(i,p :=2;while(i%p>0,p=p+1);i log(p)floor pow(p))
```
[Try it online!](https://tio.run/##FY5BCoMwFET3/xQfoZBQF/5ETazYI/QEbizVGojmoxaPn8aBgXnDLMaFOOGjwz4u4zGHj3A5J1btOTs/CnfjZ5Fzx3eSrUMfvoLl5EPYkMOZsoxZCRZUBcpA2QApSq5AlxpIawJ9EdW2MGCVrq66pqJKq6a0hgxluLN3h8j6NZO4DJwuACZNwuGwv37Le9wk8ubWw68g4x8 "Io – Try It Online")
[Answer]
**APL (NARS2000 0.5.14), 9 characters 8 characters (thanks to gurus in APL Orchard):**
```
(⍴*1∘↑)π
```
**How it works:**
Take input 8 as example. `π` breaks down 8 into vector of prime factors `2 2 2`. The [fork](http://help.dyalog.com/17.0/Content/Language/Introduction/Trains.htm) `⍴*1∘↑` takes one element from `2 2 2` as exponent, applies this to length of vector `2 2 2` which is `3`, giving `3^2 = 9`.
[Answer]
# [Factor](https://factorcode.org/) + `math.primes.factors`, 34 bytes
```
[ factors dup length swap last ^ ]
```
[Try it online!](https://tio.run/##NY5NDoIwEIX3PcWcgFDKT9EDGDdujCujSVOLEKBgO8QY49lr08Is5s3ke28yjZA4GXc5H0@HHYwC22Q23ahs0gRiwarXorRUFnpltBqiqVm0xG7SFmajED8@pBH2hHwJ@MpD56FnRZQqkjoIzeiqkbKcxZ2xCNhGaMnTGOUZKzZbSdNivVDnvKIVJT/irrB9/VhmGJR@Ygv2LfwsLMIdbm70i0Uh@8T9AQ "Factor – Try It Online")
[Answer]
# [Desmos](https://desmos.com/calculator), ~~61~~ 10+38=48 bytes
```
l=log_m(n)
\sum_{m=2}^{n-1}(sign(l-ceil(l))+1)l^m
```
[View it online](https://www.desmos.com/calculator/ym7ev8es6e) (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.
[Answer]
# [Husk](https://github.com/barbuz/Husk), 5 bytes
```
§^←Lp
```
[Try it online!](https://tio.run/##yygtzv7//9DyuEdtE3wK/v//b2hsbAgA "Husk – Try It Online")
]