#GL0000330. Loại bỏ phần tử bằng phép AND (Array Elimination)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Loại bỏ phần tử bằng phép AND (Array Elimination)
Array Elimination
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Given an array of nonnegative integers , an elimination operation with a fixed parameter () is defined as follows:
- Choose exactly distinct positions.
- Compute , the bitwise AND of the values at those positions.
- Subtract from each selected array element; all other elements remain unchanged.
Choose once before performing any operations, and keep the same throughout. Find all values for which the whole array can become zero after finitely many operations. Print them in increasing order.
PHOJ input adaptation: Each file contains one array, omitting the original Codeforces leading number of test cases .
Input
The first line contains . The second line contains nonnegative integers .
Output
Print all valid values of on one line, separated by spaces, in ascending order.
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; .
- Subtask 3 (50 points): ; .
Examples
Example 1
Input
4
4 4 4 4
Output
1 2 4
Explanation
The bit worth occurs in all four elements. The four occurrences must be partitionable into groups of size , so the allowed positive divisors are .
Example 2
Input
4
13 7 25 19
Output
1 2
Explanation
Across bit positions , the counts of set bits are . Their GCD is , so or .
Example 3
Input
5
0 0 0 0 0
Output
1 2 3 4 5
Explanation
The array is already zero, so no operations are required; every from to is valid.