AND and OR
Time limit1sMemory limit1024 MB
Given N numbers, repeatedly replace any two by two non-negative integers with the same bitwise AND and OR, and minimize the product modulo 1e9+7.
- Level
Medium7 of 10
- Topics
- Bit manipulation, Greedy, Math, Sorting
- Solved
- No attempts yet
Problem
You are given numbers. You may perform the following operation any number of times.
- Choose two numbers and replace them with two non-negative integers whose bitwise AND and bitwise OR both equal those of the two chosen numbers.
After performing operations, you want to minimize the product of the numbers. Find the minimized product of the numbers. Since the product can be very large, output its remainder modulo instead.
See the Hint section for an explanation of bitwise AND and bitwise OR.
Input
The first line contains an integer between and .
The second line contains positive integers separated by spaces. Each integer is less than .
Output
Print the remainder of the minimized product modulo on the first line.
Note that you are not minimizing the remainder of the product modulo .
Hint
A bitwise operation applies the operation to each bit position.
For example, suppose we bitwise AND and . First, write and in binary so the bits are clear.
Take the bit at each position in order, apply AND, and write the result below. For AND, the result is 1 only when both bits are 1; otherwise it is 0.
Bitwise OR works the same way. For OR, the result is 0 only when both bits are 0; otherwise it is 1.