ProgrammingHardGATE CS · Campus placements
Six people stand in a circle numbered 1 to 6; starting from 1, every second person is removed until one remains. Which number survives? This is the Josephus problem with n = 6 and k = 2.
- A. 1
- B. 6
- C. 5
- D. 3
Correct answer: C. 5
The removal order is 2, 4, 6, 3, 1, leaving 5. The recurrence J(n) = (J(n-1) + 2) mod n confirms the same survivor.
More C Programming questions
- Seven people stand in a circle numbered 1 to 7. Starting from person 1, every third person is removed until one remains. Which number…
- unsigned char a = 200, b = 100; unsigned char c = a + b; printf("%d", c); What is printed?
- In C99 and later, what are the values of (-7) / 2 and (-7) % 2?
- The modular inverse of 3 modulo 1000000007 is which value?
- Which expression is correct for (a b) % MOD with MOD = 1000000007 and 0 <= a, b < MOD, to avoid overflow in C?
- How many times does the loop x &= x - 1 run for x = 0b101100 before x becomes 0?