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.

Given a positive integer n, output the largest squarefree number which divides n.

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 . Shortest answer in bytes wins.

Standard loopholes apply.

Reference

• ...and is called the radical - so 1980's! – Jonathan Allan May 11 '17 at 16:14
• Closely related, just multiply the two outputs. Edit: Never mind, it only matches on cubefree numbers. – xnor May 11 '17 at 20:13

05AB1E, 2 bytes

fP

Try it online!

How it works

f   Implicitly take input and compute the integer's unique prime factors.
P  Take the product.
• >_> really...?? – HyperNeutrino May 11 '17 at 16:02
• @HyperNeutrino yep - if a number is not square-free it is because some of its prime factor(s) have multiplicity. – Jonathan Allan May 11 '17 at 16:07
• @JonathanAllan I'm just interested in the built-in for unique prime factors. I wish Jelly had one of those... – HyperNeutrino May 11 '17 at 16:09
• @HyperNeutrino It's 05AB1E, get used to it. 05AB1E has some really redundant builtins that apparently save bytes. – Erik the Outgolfer May 11 '17 at 16:33
• Correction, "save bytes", there's no probably about it. – Draco18s May 11 '17 at 21:43

Brachylog, 3 bytes

ḋd×

Try it online!

A very original answer...

Explanation

ḋ          Take the prime factors of the Input
d         Remove duplicates
×        Multiply
• Again, Brachylog beats Jelly because a two-byte atom is only one byte here. >:-P – HyperNeutrino May 11 '17 at 16:21
• Jelly having a lot of builtins is often seen as an advantage; but more builtins means that they need longer names on average. So there are tradeoffs involved in golfing language design. – user62131 May 11 '17 at 17:44
• I'm not trying to be "that guy", and maybe I just misunderstand byte counting, but isn't this 6 bytes? mothereff.in/byte-counter#ḋd× – Captain Man May 11 '17 at 18:15
• @CaptainMan Brachylog uses a 256 chars custom code page which you can find here. – Fatalize May 11 '17 at 18:16

JavaScript (ES6), 555450 46 bytes

Quoting OEIS:
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));
}

• Nice approach to the problem, esp. given lack of builtin factorization – Riking May 13 '17 at 16:42

MATL, 6 4 bytes

2 bytes saved with help from @LeakyNun

Yfup

Try it online!

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
• Out-golfed – Leaky Nun May 11 '17 at 16:01
• @LeakyNun Heh, I was about to post that :-) Thanks – Luis Mendo May 11 '17 at 16:03

Jelly, 4 bytes

ÆfQP

Try it online!

ÆfQP  Main link, argument is z
Æf    Takes the prime factors of z
Q   Returns the unique elements of z
P  Takes the product

CJam, 8 bytes

rimf_&:*

Why does every operation in this program have to be 2 bytes -_-

Try it online!

ri       e# Read int from input
mf     e# Get the prime factors
_&   e# Deduplicate
:* e# Take the product of the list
• I couldn't find a way to deduplicate. Nice! – Luis Mendo May 11 '17 at 16:17
• @LuisMendo I just discovered that recently. I always thought it was multiset intersection but apparently it's just normal set intersection. – Business Cat May 11 '17 at 16:18

Retina, 3630 28 bytes

+((^|\3)(^(1+?)|\3\4))+3

Input and output in unary.

Try it online! (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))+$

Try it online!

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!

*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
• You can use *F+1{P instead. – Leaky Nun May 11 '17 at 17:40

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;}
• I think you can shorten it by removing r and instead use while(n%(d*d)<1)n/=d;. – Ørjan Johansen May 16 '17 at 0:55
• @ØrjanJohansen That seems right. I was thinking construction rather than reduction. I have some additional improvements to add, will update soon. – algmyr May 16 '17 at 1:40
• ++d*d is absolutely not well defined by the C standards - it's a classic case of explicitly undefined behavior. But we're going by implementations here, anyway. – Ørjan Johansen May 16 '17 at 2:35
• Actually, shouldn't d++<n, which is well defined, still work? I think the old version went all the way to n+1 (harmlessly). – Ørjan Johansen May 16 '17 at 2:45
• You're probably right about the undefined behavior. For some reason I thought that operator precedence would solve that. Most examples I've seen of UB uses same priority operators, but of course there is a data race here as well. You're also right about d++<n being correct, for some reason I didn't see that when I rewrote the code. – algmyr May 16 '17 at 3:10

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

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.

• This outputs 12 when I input 12. – Flounderer May 12 '17 at 4:09
• @Flounderer you are correct, I have updated the code. – Giuseppe May 12 '17 at 15:35

Actually, 2 bytes

Try it online!

Explanation:

yπ
y   prime divisors
π  product

Pari/GP, 28 bytes

n->factorback(factor(n)[,1])

Try it online!

Pyt, 3 bytes

←ϼΠ

Explanation:

←                  Get input
ϼ                 Get list of unique prime factors
Π                Compute product of list
Implicit print