Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- There is a Swiss bank, which has many lockers in their underground vault. The lockers are numbered from 1 to N, initially all locked. A genius thief somehow managed to enter the vault, and now wants to open all the lockers with his magical key.
- Now this thief is kind of crazy. Instead of opening all the lockers serially from 1 to N, he decides to open them in multiple passes!
- On the first pass, he opens the first unopened locker (which is always locker #1 in the first pass), and every second unopened lockers thereafter.
- On the second pass, he opens the first unopened locker, and every third unopened lockers thereafter.
- So basically, on the nth pass, he opens the first unopened locker, and every (n+1)th unopened lockers thereafter.
- Say, there are 9 lockers.
- On the first pass - he opens 1, 3, 5, 7, and 9. At this stage, these lockers are still closed: 2, 4, 6, and 8.
- On the second pass - he opens 2 and 8. At this stage, these lockers are still closed: 4 and 6.
- On the third pass - he opens locker 4. At this stage, only locker 6 is still closed.
- On the final pass, he opens locker 6. Now all the lockers are open.
- Input
- A number N (1<=N<=2000) representing the number of lockers.
- Output
- Print the number of the locker opened last.
- Two Sample Inputs
- 9
- 42
- Two Sample Outputs
- 6
- 42
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement