Skip to main content
Commonmark migration
Source Link

#R, 52 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.

#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.

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.

deleted 38 characters in body
Source Link
Giuseppe
  • 28.8k
  • 3
  • 31
  • 105

#R, 5152 bytes

s=1:`if`((n=scan());f=s[!s%in%s^2];max<2,1,prod(maxunique(f[n%%f<1]),c(1,gmp::factorize(n))))

reads n from stdin. requires twoRequires the maxgmp calls sincelibrary to be installed (so TIO won't work). Uses the way I've done itsame approach as many of the above answers, but it crashes on an input of 1 returns -Inf for the first, because maxfactorize(1). returns an empty vector of class fbigz is the first, which crashes nunique integers that aren't squares, alas.

Try it online

#R, 51 bytes

s=1:(n=scan());f=s[!s%in%s^2];max(max(f[n%%f<1]),1)

reads n from stdin. requires two max calls since the way I've done it, an input of 1 returns -Inf for the first max. f is the first n integers that aren't squares.

Try it online

#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.

Post Undeleted by Giuseppe
Post Deleted by Giuseppe
Source Link
Giuseppe
  • 28.8k
  • 3
  • 31
  • 105

#R, 51 bytes

s=1:(n=scan());f=s[!s%in%s^2];max(max(f[n%%f<1]),1)

reads n from stdin. requires two max calls since the way I've done it, an input of 1 returns -Inf for the first max. f is the first n integers that aren't squares.

Try it online