Talk:UVa 10015 - Joseph's Cousin

Linked list as optimal data structure?
An order statistics tree would be a much better data structure, giving O(lg(n)) time for both search by rank and deletion.

The CLRS book has more information about them.

Rrenaud 12:56, 11 March 2008 (EDT)

There's also an $$O(n)$$ math solution without any simulation: s = 0 for i from 1 to n: s = (s + prime[n - i]) % i;      // prime[i] is (i+1)st prime print s + 1 Sweepline 13:40, 11 March 2008 (EDT)