#P11180. Deletion of Numbers
Deletion of Numbers
Deletion of Numbers
This problem is adapted from ROI 2018 Regional, Day2 T1 (Удаление чисел).
You are given a sequence of natural numbers from \(1\) to \(n\) and a natural number \(k\). In one or more operations, you delete numbers from the sequence as follows: In each operation, consider the remaining numbers in increasing order and delete every \(k\text{-th}\) number. If, after an operation, the number of remaining numbers is less than \(k\), the deletion process stops.
Your task is to determine during which operation the number \(n\) is deleted, or output \(-1\) if \(n\) is never deleted before the process stops.
For example, let \(n=13\) and \(k=2\):
- Operation 1 removes: 2, 4, 6, 8, 10, 12. Remaining numbers: 1, 3, 5, 7, 9, 11, 13.
- Operation 2 removes: 3, 7, 11. Remaining numbers: 1, 5, 9, 13.
- Operation 3 removes: 5, 13. Remaining numbers: 1, 9.
- Operation 4 removes: 9. Remaining number: 1. Process stops because only one number remains.
Thus, the number \(13\) is deleted in operation \(3\).
inputFormat
The input consists of a single line containing two space-separated natural numbers (n) and (k) ((1 \leq n, k \leq 10^5)).
outputFormat
Output a single integer representing the operation number in which (n) is deleted. If (n) is never deleted, output (-1).
sample
13 2
3