OFFSET
1,2
COMMENTS
Start with the natural numbers:
1 2 3 4 5 6 7 8 9 10 11 ...
Accept the 2nd number, 2 and erase every 2nd number after it, giving:
1 2 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 ...
Accept the 3rd number, 3 and erase every 3rd number after it, giving:
1 2 3 5 7 11 13 17 19 23 25 29 31 35 ...
Accept the 4th number, 5 and erase every 4th number after it, giving:
1 2 3 5 7 11 13 19 23 25 31 35 ...
Repeat!
LINKS
Reinhard Zumkeller, Table of n, a(n) for n = 1..10000
PROG
(Tcl) source /tclutils/utils.tcl
set l [range 0 10000]; set z z
for {set i 2} {$i*2 <= [llength $l]} {incr i} {
set k [expr {[llength $l]-1}]
set k [expr {$k - ($k % $i)}]
while {$k > $i} {
set l [lreplace $l $k $k]
incr k -$i
}
puts "after $i: length [llength $l], prefix [join [lrange $l 0 10] { }]"
}
(Haskell)
a108696 n = a108696_list !! (n-1)
a108696_list = 1 : sieve' 2 [2..] where
sieve' n (x:xs) = x : (sieve' (n+1) $ sieving xs) where
sieving xs = (take (n-1) xs) ++ (sieving $ drop n xs)
-- Reinhard Zumkeller, Jul 04 2011
CROSSREFS
KEYWORD
nonn
AUTHOR
David Applegate, Oct 11 2007
STATUS
approved