Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- You've just moved into a new house which is haunted by playful ghosts. You brought your N drawers there, numbered from 1 to N. Initially all the drawers were closed.
- Tired after a long day, you went to bed to spent your 0th night in your new home. Unfortunately the ghosts don't sleep at nights. Starting from the 1st night, every kth night the ghosts came out of their hiding and changed the state of all the drawers whose numbers were divisible by k, i.e. opened the closed drawers and closed the open ones.
- After exactly N nights you decided to sell the drawers with numbers in range [A, B]. Obviously you want the drawers to be closed before selling. Find out which drawers in range [A, B] should be closed after the Nth night.
- Example:
- For N = 5, A = 1 and B = 5 the answer is [1, 4].
- Here are drawers' states after each night (0 denotes closed drawers and 1 denotes open ones):
- 0) 00000
- 1) 11111
- 2) 10101
- 3) 10001
- 4) 10011
- 5) 10010
- So the first and the fourth drawers will be opened after five nights.
- [input] integer N
- The number of drawers and nights spent in the house. 1 ≤ N ≤ 106.
- [input] integer A
- The minimum number of the drawers to be sold.
- [input] integer B
- The maximum number of the drawers to be sold. 1 ≤ A ≤ B ≤ N.
- [output] array.integer
- List of the drawers that should be closed.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement