Question: How to compute an integer sequence using divisor function and least unused term

Requesting a code to compute (and graph) the following self referencing sequence:

a(1)=1. If a(n) is a novel term (seen for the first time) then a(n+1)= d(a(n)) where d(k) is the number of divisors of k. 
if a(n) has been seen before then a(n+1) = a(n)+m where m is the least prior term which has not already been used in this way (once m is used it cannot be used again).

Sequence starts:

1,1,2,2,3,2,4,3,5,2,4,6,4,7,2,5,7,11,2...,

note that there are often multiple copies of the least unused term, which might make accounting for them tricky. 

Thanks in advance 

 

 

Please Wait...