#K61467. Concatenated Book Stacks Page Finder
Concatenated Book Stacks Page Finder
Concatenated Book Stacks Page Finder
You are given an infinite series of book stacks. The first stack consists of 1 book, the second stack of 2 books, the third stack of 3 books, and so on. All these stacks are concatenated one after the other to form a single sequence of books. The page numbers of the books are assigned sequentially within each stack.
For the i-th stack (where i
starts from 1), the first page number is given by the formula:
Given a zero-based index \( n \) that refers to the position of a book in the concatenated sequence, your task is to compute its page number.
Example: The first few books are assigned page numbers as follows:
- Index 0: Page 1 (from stack 1)
- Index 1: Page 2 (first book of stack 2)
- Index 2: Page 3 (second book of stack 2)
- Index 3: Page 4 (first book of stack 3)
- Index 4: Page 5 (second book of stack 3)
- Index 5: Page 6 (third book of stack 3)
Your goal is to determine the page number for any given index in this sequence.
inputFormat
The input consists of a single integer \( n \) (\( 0 \leq n \lt 10^9 \)) provided via standard input, representing the zero-based index in the concatenated sequence of books.
outputFormat
Output a single integer which is the page number of the book at the given index. The output should be printed to standard output.
## sample0
1