Codeforces Round 1133 (Div. 1, Div. 2) is coming soon! Register here. ×

Microsoft SDE Intern Interview 2026 – Infinite Sequence Elimination

Revision en1, by sj02012006, 2026-01-24 05:52:14

You are given an infinite sequence of positive integers: 1, 2, 3, 4, 5, 6, 7, 8, ...

An infinite number of operations are performed on this sequence: In the 1st operation, every 2nd element is removed. In the 2nd operation, every 3rd element of the remaining sequence is removed. In the 3rd operation, every 4th element is removed. In the i-th operation, every (i + 1)-th element is removed. These operations continue indefinitely.

You are given an integer x. Determine whether x will remain in the sequence forever or be removed at some operation.

Input : 13

1,2,3,4,5,6,7,8,9,10,11,12,13

1st operation (remove every 2nd):

1,3,5,7,9,11,13

2nd operation (remove every 3rd):

1,3,7,9,13

3rd operation (remove every 4th):

1,3,7,13

4th operation (remove every 5th): No 5th element exists

Answer: YES

Input : 17

Answer: NO

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English sj02012006 2026-01-24 05:52:14 935 Initial revision (published)