A375118 Let {b(m)} be Recamán's sequence A005132, with the additional term b(-1):=0. Define a(n) to be the first index m where b(m-1)-m = -n, or -1 if b(m-1)-m never equals -n.
0, 1, 181695, 5, 1523, 137, 15, 1525, 139, 17, 1527, 141, 28, 1529, 143, 30, 1531, 145, 32, 1533, 147, 53, 1535, 149, 55, 1537, 151, 57, 1539, 153, 59, 1541, 155, 61, 1543, 157, 63, 1545, 159, 65, 1547, 161, 276, 1549, 163, 278, 1551, 165, 280, 1553, 167, 282
Offset: 0
Keywords
Examples
Recamán's sequence {b(m)} begins with 0, 1, 3, 6, 2, 7, 13,... b(1-1)-1 = 0-1 = -1, so a(1) = 1. b(5-1)-5 = 2-5 = -3, so a(3) = 5.
Programs
-
Python
def a(n): a = [0] for i in range(1,n): a+=[-1] countA = 1 seq = [0] m = 1 while(countA < n): x = seq[m-1]-m if(x<0): if(-x < n and a[-x]==-1): a[-x] = m countA+=1 seq+=[seq[m-1]+m] else: if(x not in seq): seq+=[x] else: seq+=[seq[m-1]+m] m+=1 return a #find all terms in range(0,n)
Comments