Process Tree

Company: MERCARI JAPAN

Difficulty: easy

Problem Statement

Process Tree A hypothetical chain of processes is represented as a tree. Processes are numbered starting at 1 , incremented by 1 . Every process spawns a number of child processes equal to its own process number: the first node, process number 1 , spawns 1 process, the second spawns 2 processes, the third spawns 3 processes, and so on. Processes are created in order. Process 1 is the root. Then process 1 spawns its 1 child, which receives the next unused number 2 . Then process 2 spawns its 2 children, which receive the next unused numbers 3 and 4 . Then process 3 spawns its 3 children, which receive 5 , 6 and 7 . The tree therefore begins like this: 1 └── 2 ├── 3 │ ├── 5 │ ├── 6 │ └── 7 └── 4 ├── 8 ├── 9 ├── 10 └── 11 Given a process number, find the process number of its parent. Input Format The input consists of a single line: The line contains a single integer processNumber , the process number to query. Input will be read from the STDIN by the candidate. Output Format Print a sing