OFFSET
1,2
COMMENTS
This sequence is a self-inverse permutation of the positive integers.
LINKS
FORMULA
a(n) = n iff n = 1 or n is a prime number.
EXAMPLE
The first terms are:
n a(n) gcd(n, a(n))
-- ---- ------------
1 1 1
2 2 2
3 3 3
4 6 2
5 5 5
6 4 2
7 7 7
8 10 2
9 12 3
10 8 2
11 11 11
12 9 3
13 13 13
14 16 2
PROG
(PARI) s=0; for (n=1, 67, for (v=1, oo, if (!bittest(s, v) && (n==1 || isprime(gcd(n, v))), print1 (v", "); s+=2^v; break)))
(Python)
from math import gcd
from sympy import isprime
from itertools import count, islice
def agen(): # generator of terms
aset, mink = {1}, 2; yield 1
for n in count(2):
k = mink
while k in aset or not isprime(gcd(n, k)): k += 1
aset.add(k); yield k
while mink in aset: mink += 1
print(list(islice(agen(), 67))) # Michael S. Branicky, May 23 2022
CROSSREFS
KEYWORD
nonn
AUTHOR
Rémy Sigrist, May 20 2022
STATUS
approved