Operator Party
Time limit2sMemory limit512 MB
Starting from X = 0, apply the operations for multiples of A to F at each step i from 1 to N, in the given priority order, and print the final X.
- Level
Hard8 of 10
- Topics
- Math, Bit manipulation, Simulation
- Solved
- No attempts yet
Problem
A variable that holds an integer starts at .
For each from to , increasing by each time, perform the operations that match the conditions below. After finishing all operations up to , print the final value of .
- If is a multiple of , do = + . (+ is the addition operator.)
- If is a multiple of , do = % . (% is the remainder operator.)
- If is a multiple of , do = & . (& is the bitwise AND operator.)
- If is a multiple of , do = ⊕ . (⊕ is the bitwise XOR operator.)
- If is a multiple of , do = | . (| is the bitwise OR operator.)
- If is a multiple of , do = >> . (>> is the bitwise right shift operator.)
- When several operations apply at once, perform them in the priority order +, %, &, ⊕, |, >>.
Input
The first line contains .
The second line contains , , , , , and , separated by spaces.
Output
Print the final value of .
Constraints
- , , , , , , and are positive integers.
Hint
Bitwise operators work on each bit separately.
Bitwise AND
For each pair of bits, the result bit is only when both bits are . Otherwise it is .
Example:
Bitwise XOR
For each pair of bits, the result bit is when the two bits differ. Otherwise it is .
Example:
Bitwise OR
For each pair of bits, the result bit is when at least one of the bits is . Otherwise it is .
Example:
Bitwise right shift
For >> , the bits of move places to the right. The bits that open up on the left are filled with .
Example: