Oops... My formula... it's wrong, of course. Nevertheless, without modular-arithmetic notation, we can write sufficient condition as

(

is defined above.) E.g. in the case of

and

we have

, consequently

, thus, desired arrangement with such a parameters is impossible... Feel free to play with this formula, I think it's close to the true solution... :)