solving Josephus problem