top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is the last number, if we delete nth number of a circle ?

+4 votes
777 views

If we delete the mth number from a circle which is composed of numbers 0, 1, …, n-1 counting from 0 at every time, what is the last number?

For example, a circle is composed of five numbers 0, 1, 2, 3, 4. If we delete the 3rd number at every time, the deleted numbers are in order of 2, 0, 4, 1, so the last remaining number is 3.

posted Dec 12, 2013 by Diya Sharma

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

Its called Josephus problem http://en.wikipedia.org/wiki/Josephus_problem

int remaining(int n, int k) {
    int i, r = 0;
    for (i = 2; i <= n; i++)
        r = (r + k) % i;

    return r;
}

main()
{
    printf("%d\n", remaining(5, 3));
}
answer Dec 12, 2013 by Luv Kumar
...