News for hackers. Stuff that matters.
Re:Data structures and algorithms problems in C++ using STL by throwaput on Friday March 10, 2017 @01:06PM (#13840645)
On the first glance the first problem seems quite impossible. For example, if n is power of two, then for each prime number < n there will be a cycle starting with that number. If n is not a power of two, I haven't yet seen any good explanation of cycles. Any hints? We can't use a or b in any way?
Re:Data structures and algorithms problems in C++ using STL by davidtgoldblatt on Friday March 10, 2017 @02:24PM (#13841265)
I think you're on the right track (i.e. viewing it as a permutation, and looking at the cycle decomposition of that permutation).

Try indexing from 0 instead of 1 if you're not. Then the cycle containing 1 will start with (1, 2, 4, 8, ...). What happens when it wraps around?

Re:Data structures and algorithms problems in C++ using STL by throwaput on Friday March 10, 2017 @01:11PM (#13840673)
Even for power of two it's not correct, forget my statement about cycles.
Re:Data structures and algorithms problems in C++ using STL by throwaput on Friday March 10, 2017 @01:22PM (#13840758)
Yet I have only one idea - that we can permute the elements somehow (in a O(1) reversible way like a Gray code) so that the cycles would form something computable in O(n) time and O(1) space