[Question]
  [
# Definitions
* A **perfect square** is an integer which can be expressed as the square of another integer. For example, `36` is a perfect square because `6^2 = 36`.
* A **squarefree number** is an integer which is not divisible by any perfect square, except by `1`. For example, `10` is a squarefree number. However, `12` is not a squarefree number, because `12` is divisible by `4` and `4` is a perfect square.
# Task
Given a positive integer `n`, output the largest squarefree number which divides `n`.
# Testcases
```
n   output
1   1
2   2
3   3
4   2
5   5
6   6
7   7
8   2
9   3
10  10
11  11
12  6
13  13
14  14
15  15
16  2
17  17
18  6
19  19
20  10
21  21
22  22
23  23
24  6
25  5
26  26
27  3
28  14
29  29
30  30
31  31
32  2
33  33
34  34
35  35
36  6
37  37
38  38
39  39
40  10
41  41
42  42
43  43
44  22
45  15
46  46
47  47
48  6
49  7
50  10
```
# Scoring
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"). Shortest answer in bytes wins.
[Standard loopholes](https://codegolf.meta.stackexchange.com/questions/1061/loopholes-that-are-forbidden-by-default) apply.
# Reference
* [OEIS A007947](http://oeis.org/A007947)
  
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 2 bytes
```
fP
```
[Try it online!](https://tio.run/nexus/05ab1e#@58W8P@/iQUA "05AB1E – TIO Nexus")
### How it works
```
f   Implicitly take input and compute the integer's unique prime factors.
 P  Take the product.
```
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), 3 bytes
```
ḋd×
```
[Try it online!](https://tio.run/nexus/brachylog2#@/9wR3fK4en//xsZ/I8CAA "Brachylog – TIO Nexus")
A very original answer...
### Explanation
```
ḋ          Take the prime factors of the Input
 d         Remove duplicates
  ×        Multiply
```
[Answer]
## JavaScript (ES6), ~~55~~ ~~54~~ ~~50~~ 46 bytes
Quoting [OEIS](http://oeis.org/A007947):  
*a(n) is the smallest divisor u of n such that n divides u^n*
Updated implementation:  
*a(n) is the smallest ~~divisor u of n~~ positive integer u such that n divides u^n*
```
let f =
n=>(g=(p,i=n)=>i--?g(p*p%n,i):p?g(++u):u)(u=1)
for(n = 1; n <= 50; n++) {
  console.log(n,f(n));
}
```
[Answer]
# [MATL](https://github.com/lmendo/MATL), ~~6~~ 4 bytes
*2 bytes saved with help from @LeakyNun*
```
Yfup
```
[Try it online!](https://tio.run/nexus/matl#@x@ZVlrw/7@JBQA "MATL – TIO Nexus")
### Explanation
Consider input `48`.
```
Yf   % Implicit input. Push prime factors with repetitions.  STACK: [2 2 2 2 3]
u    % Unique.                                               STACK: [2 3]
p    % Product of array. Implicit display.                   STACK: 6
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 4 bytes
```
ÆfQP
```
[Try it online!](https://tio.run/nexus/jelly#@3@4LS0w4P/h9kdNa/7/jza00FEwMgBiEyA2BWIg38QiFgA "Jelly – TIO Nexus")
```
ÆfQP  Main link, argument is z
Æf    Takes the prime factors of z
  Q   Returns the unique elements of z
   P  Takes the product
```
[Answer]
# [CJam](https://sourceforge.net/p/cjam), 8 bytes
```
rimf_&:*
```
Why does every operation in this program have to be 2 bytes -\_-
[Try it online!](https://tio.run/nexus/cjam#@1@UmZsWr2al9f@/OQA "CJam – TIO Nexus")
```
ri       e# Read int from input
  mf     e# Get the prime factors
    _&   e# Deduplicate
      :* e# Take the product of the list
```
[Answer]
## [Retina](https://github.com/m-ender/retina), ~~36~~ ~~30~~ 28 bytes
```
+`((^|\3)(^(1+?)|\3\4))+$
$3
```
Input and output [in unary](http://meta.codegolf.stackexchange.com/questions/5343/can-numeric-input-output-be-in-unary).
[Try it online!](https://tio.run/nexus/retina#DY27DcMwEMV6zuEAUgQEenenX5VFDMODZHdHHRuSr3R/Csf7KXdK1@/0nK6k8s0bz8i5HBz@6BGGEzQ6g8lCFQkZchSooY4GmmhhFduOYY4F1rCODWxiC6@48J10PPCGd3zgE19EJUQYsY9BNKITg5jEotU/ "Retina – TIO Nexus") (Includes a header and footer for decimal <-> unary conversion and to run multiple test cases at once.)
### Explanation
The idea is to match the input as a square times some factor. The basic regex for matching a square uses a forward-reference to match sums of consecutive odd integers:
```
(^1|11\1)+$
```
Since we don't want to match perfect squares, but numbers that are divisible by a square, we replace that `1` with a backreference itself:
```
(^(1+?)|\1\2\2)+$
```
So now the outer group `1` will be used **n** times where **n2** is the largest square that divides the input and group `2` stores the remaining factor. What we want is to divide the integer by **n** to remove the square. The result can be expressed as the number of iterations of group `1` times group `2`, but this is a bit tricky to do. Retina's `$*` will probably soon be improved to take a non-character token as its right hand argument in which case we could simply replace this with `$#1$*$2`, but that doesn't work yet.
Instead, we decompose the odd numbers differently. Let's go back to the simpler example of matching perfect squares with `(^1|11\1)+$`. Instead of having a counter `\1` which is initialised to **1** and incremented by **2** on each iteration, we'll have two counters. One is initialised to **0** and one is initialised to **1**, and they're both incremented by **1** on each iteration. So we've basically decomposed the odd numbers **2n+1** into **(n) + (n+1)**. The benefit is that we'll end up with **n** in one of the groups. In its simplest form, that looks like this:
```
((^|1\2)(^1|1\3))+$
```
Where `\2` is **n** and `\3` is **n+1**. However, we can do this a bit more efficiently by noticing that the **n+1** of one iteration is equal to the **n** of the next iteration, so we can save on a `1` here:
```
((^|\3)(^1|1\3))+$
```
Now we just need to go back to using an initial factor instead of `1` to match inputs that are divided by a perfect square:
```
((^|\3)(^(1+?)|\3\4))+$
```
Now all we need to do is replace this entire thing with `$3` at the end, which stores the initial factor times the number of steps, which drops one factor of the square from the input.
This is done repeatedly with the `+` at the very beginning of the program, to account for inputs that contain higher powers than squares.
[Answer]
# Octave, 27 bytes
```
@(x)prod(unique(factor(x)))
```
Similar approach as the other answers. The difference is: The functions have much longer names. I believe the code explains itself really:
Takes the `prod`uct of the `unique` prime `factor`s of a number.
[Answer]
# Wolfram Language, ~~29~~ 28 bytes
-1 Thanks to [@Martin Ender ♦](https://codegolf.stackexchange.com/users/8478/martin-ender)
```
Most[1##&@@FactorInteger@#]&
```
**Explanation:**
```
           FactorInteger@#    (*Get prime factorization as {{a,b},{c,d}}*)
     1##&@@                   (*Multiply list elements together, to get the product of the factors and the product of their exponents*)
Most[                     ]&  (*Take the first element*)
```
[Answer]
# [Python](https://docs.python.org/2/), 37 bytes
```
f=lambda n,r=1:1>>r**n%n or-~f(n,r+1)
```
[Try it online!](https://tio.run/nexus/python2#@59mm5OYm5SSqJCnU2RraGVoZ1ekpZWnmqeQX6Rbl6YBFNU21Pyfll@kkKeQmadQlJiXnqphqGNqoGnFxVlQlJlXAtSpAFSo@R8A "Python 2 – TIO Nexus")
The largest squarefree divisor of `n` is that smallest number `r` with all of `n`'s prime factors. We can check this as `r**n%n==0`, since `r**n` make `n` copies of each prime factor of `r`, and is divisible by `n` only if each of `n`'s prime factors is represented.
The `1>>r**n%n` is equivalent to `int(r**n%n==0)`. If `True` can be used output 1, it's 2 bytes shorter to do.
```
f=lambda n,r=1:r**n%n<1or-~f(n,r+1)
```
[Answer]
# [Mathics](http://mathics.github.io/), 40 bytes
```
Times@@(Transpose@FactorInteger@#)[[1]]&
```
[Try it online!](https://tio.run/nexus/mathics#S7P9H5KZm1rs4KARUpSYV1yQX5zq4JaYXJJf5JlXkpqeWuSgrBkdbRgbq/Y/oCgzr8QhzcHY7D8A "Mathics – TIO Nexus")
[Answer]
## [Alice](https://github.com/m-ender/alice), 4 bytes
```
iDo@
```
[Try it online!](https://tio.run/nexus/alice#@5/pku/w/38yAA "Alice – TIO Nexus")
Input and output are given [as the code point of a character](http://meta.codegolf.stackexchange.com/questions/4708/can-numeric-input-output-be-in-the-form-of-byte-values) (works for all valid Unicode code points).
### Explanation
Well, Alice has a built-in `D` whose definition is "Deduplicate prime factors". That is, as long as a value is divisible by some **p2** for a prime **p**, divide that value by **p**. This happens to be exactly the function required in this challenge. The rest is just input, output, terminate the program.
The reason this was added to Alice actually has nothing to do with this integer sequence. I was trying to stick to a theme of associating divisors with substrings and prime factors with characters. And I needed a function that goes with "deduplicate characters" (which is much more useful in general, because it let's you treat strings as sets, especially when used together with the various multiset operators).
[Answer]
# [Haskell](https://www.haskell.org/), 31 bytes
```
f n=until(\r->r^n`mod`n<1)(+1)1
```
[Try it online!](https://tio.run/nexus/haskell#@5@mkGdbmleSmaMRU6RrVxSXl5Cbn5KQZ2OoqaFtqGn4PzcxM0/BVqGgKDOvREFFIVojTydNI09TsybPRjfaUE/P1CA29j8A "Haskell – TIO Nexus")
[Answer]
# [Pyke](https://github.com/muddyfish/PYKE), 3 bytes
```
P}B
```
[Try it online!](https://tio.run/nexus/pyke#@x9Q6/T/v6ERAA "Pyke – TIO Nexus")
```
P   -   factors(input)
 }  -  uniquify(^)
  B - product(^)
```
[Answer]
# [Prolog (SWI)](http://www.swi-prolog.org), ~~84~~ 39 bytes
```
f(N,P):-between(1,N,P),P^N mod N=:=0,!.
```
[Try it online!](https://tio.run/nexus/prolog-swi#TdJNasMwEAXgfU@hZmWDY6yZ8V8g9AbGJyi0RIFCm5bakOO7z36W0t3zIM2nkbxcs6EY89PxPcz3EG6ZL9bvYnwd3Nf3xQ3n07kqnsvl5eiumXeF83mBJEiyJUXSLVmq1Uj1lhqkZkstUrulLq3r015foXPF6BGpeIm7vaK4LzVEY6wRCfkmNvUtipR8l/b3KPY8@oMSULIPBErYQGAJLbHYQOo4kqzSXmzj@aVLhxJQQkpBKSkFpaRU0t1BUjZQSMoGCkppaRN9XSlOpbC0Y4SltOwxlsEyWgbLiBkw21/K0rD2uEIDZtQMmlGzdIfWxxeso3X//ZjD5y07zGGaJ/fzNk3hcsjLJ/4u6yTjv2VjXi5/ "Prolog (SWI) – TIO Nexus")
Adapted the idea of [@xnor's Haskell answer](https://codegolf.stackexchange.com/a/120136/69074) to Prolog.
[Answer]
# PHP, 70 Bytes
```
for($r=1,$i=2;1<$n=&$argn;)$n%$i?++$i:$n/=$i+!($r%$i?$r*=$i:1);echo$r;
```
[Try it online!](https://tio.run/nexus/php#HYpNCoAgEEb33SL4isogLGjhOHiWiEo3KnN/MGv5fqzLPjc45Im87VTuJAOE9YzAK2mLyP1faUTsEJxSCAZxYQTV1vVzkKmi0SNdp08QKuUF "PHP – TIO Nexus")
[Answer]
# Pyth, ~~8~~ 6 bytes
```
*F+1{P
```
\*-2 bytes thanks to @LeakyNun
Would be 3 if Pyth had a built-in for products of lists...
[Try it!](https://pyth.herokuapp.com/?code=%2aF%2B1%7BP&input=12&test_suite=1&test_suite_input=1%0A2%0A3%0A4%0A5%0A6%0A7%0A8%0A9%0A10%0A11%0A12%0A13%0A14%0A15%0A16%0A17%0A18%0A19%0A20%0A21%0A22%0A23%0A24%0A25%0A26%0A27%0A28%0A29%0A30%0A31%0A32%0A33%0A34%0A35%0A36%0A37%0A38%0A39%0A40%0A41%0A42%0A43%0A44%0A45%0A46%0A47%0A48%0A49%0A50&debug=0)
```
*F+1{P
      Q     # Implicit input
     P      # Prime factors of the input
    {       # Deduplicate
  +1        # Prepend 1 to the list (for the case Q==1)
*F          # Fold * over the list
```
[Answer]
# C, ~~65~~ 50 bytes
Thanks to @Ørjan Johansen for removing the need for `r`. Thanks to this and some other dirty tricks I was able to squeeze 15 bytes off!
```
d;f(n){for(d=1;d++<n;)n%(d*d)||(n/=d--);return n;}
```
`while` is gone and replaced with `||` and index twiddling. `<=` should have been `<` all along.
~~`<=` turned to `<` by moving the increment to get `n%(++d*d)` (should be well defined due to operator precedence).~~
---
Original code:
```
d;r;f(n){for(r=d=1;d++<=n;)while(n%d<1)r*=r%d?d:1,n/=d;return r;}
```
[Answer]
# Axiom, 89 bytes
```
f(x:PI):PI==(x=1=>1;g:=factor x;reduce(*,[nthFactor(g,i) for i in 1..numberOfFactors g]))
```
test and results
```
(38) -> [[i, f(i)] for i in 1..30 ]
   (38)
   [[1,1], [2,2], [3,3], [4,2], [5,5], [6,6], [7,7], [8,2], [9,3], [10,10],
    [11,11], [12,6], [13,13], [14,14], [15,15], [16,2], [17,17], [18,6],
    [19,19], [20,10], [21,21], [22,22], [23,23], [24,6], [25,5], [26,26],
    [27,3], [28,14], [29,29], [30,30]]
```
this is the one not use factor() function
```
g(x:PI):PI==(w:=sqrt(x);r:=i:=1;repeat(i:=i+1;i>w or x<2=>break;x rem i=0=>(r:=r*i;repeat(x rem i=0=>(x:=x quo i);break)));r)
```
but it is only 125 bytes
[Answer]
# R, 52 bytes
```
`if`((n=scan())<2,1,prod(unique(c(1,gmp::factorize(n))))
```
reads `n` from stdin. Requires the `gmp` library to be installed (so TIO won't work). Uses the same approach as many of the above answers, but it crashes on an input of `1`, because `factorize(1)` returns an empty vector of class `bigz`, which crashes `unique`, alas.
[Answer]
# [Actually](https://github.com/Mego/Seriously), 2 bytes
```
yπ
```
[Try it online!](https://tio.run/nexus/actually#@195vuH/fxMLAA "Actually – TIO Nexus")
Explanation:
```
yπ
y   prime divisors
 π  product
```
[Answer]
# [Pari/GP](http://pari.math.u-bordeaux.fr/), 28 bytes
```
n->factorback(factor(n)[,1])
```
[Try it online!](https://tio.run/nexus/pari-gp#S1OwVfifp2uXlphckl@UlJicrQFhauRpRusYxmr@TwOxgaoMdRRMDXQUCooy80o08nQUlBR07RSUdBTSgCo1Nf8DAA "Pari/GP – TIO Nexus")
[Answer]
# [Pyt](https://github.com/mudkip201/pyt), 3 bytes
```
←ϼΠ
```
Explanation:
```
←                  Get input
 ϼ                 Get list of unique prime factors
  Π                Compute product of list
                   Implicit print
```
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), 2 bytes
```
ǏΠ
```
[Try it Online!](https://vyxal.pythonanywhere.com/#WyIiLCLGm8O3JDoiLCLHj86gIiwiXCI6YCA9PiBgaiR04oCePWDinYzinIVgaeG6izvigYsiLCJbWzEsMV0sWzIsMl0sWzMsM10sWzQsMl0sWzUsNV0sWzYsNl0sWzcsN10sWzgsMl0sWzksM10sWzEwLDEwXSxbMTEsMTFdLFsxMiw2XSxbMTMsMTNdLFsxNCwxNF0sWzE1LDE1XSxbMTYsMl0sWzE3LDE3XSxbMTgsNl0sWzE5LDE5XSxbMjAsMTBdLFsyMSwyMV0sWzIyLDIyXSxbMjMsMjNdLFsyNCw2XSxbMjUsNV0sWzI2LDI2XSxbMjcsM10sWzI4LDE0XSxbMjksMjldLFszMCwzMF0sWzMxLDMxXSxbMzIsMl0sWzMzLDMzXSxbMzQsMzRdLFszNSwzNV0sWzM2LDZdLFszNywzN10sWzM4LDM4XSxbMzksMzldLFs0MCwxMF0sWzQxLDQxXSxbNDIsNDJdLFs0Myw0M10sWzQ0LDIyXSxbNDUsMTVdLFs0Niw0Nl0sWzQ3LDQ3XSxbNDgsNl0sWzQ5LDddLFs1MCwxMF1dIl0=)
]