OFFSET
1,2
COMMENTS
This is a permutation of the positive integers.
The squares appear in increasing order. For prime p, p^2 is immediately followed by p, 2*p, ..., (p-1)*p.
LINKS
EXAMPLE
For n = 4, a(4) is different from 1, 2, 4, and lcm(4, a(4)) is a perfect square. Therefore, a(4) = 9.
PROG
(PARI) seq(n)={my(b=1, a=vector(n), M=Map()); for(n=1, #a, my(k=1); while(!issquare(lcm(b, k)) || mapisdefined(M, k), k++); a[n]=k; b=lcm(b, k); mapput(M, k, 1)); a} \\ Andrew Howroyd, Aug 30 2024
(Python)
from math import isqrt, lcm
from itertools import count, islice
def sqr(n): return isqrt(n)**2 == n
def agen(): # generator of terms
an, aset, L, m = 1, {1}, 1, 2
for n in count(2):
yield an
an = next(k for k in count(m) if k not in aset and sqr(lcm(k, L)))
aset.add(an)
L = lcm(L, an)
while m in aset: m += 1
print(list(islice(agen(), 65))) # Michael S. Branicky, Aug 30 2024
CROSSREFS
KEYWORD
nonn,easy
AUTHOR
Yifan Xie, Aug 25 2024
STATUS
approved