Cosmin was bored during the Romanian class when the teacher mentioned a mischievous character in the story "Povestea lui Harap-Alb." This reminded Cosmin of a tricky problem he couldn't solve. If you help him solve the problem, he will send you a mischievous elf with a violin and a bow. Thus, Cosmin will understand how to solve the problem, and you will enjoy harmonious music.
Task
You are given two numbers, and , followed by an array of non-zero natural numbers, indexed from to . A new array will be constructed, where each number () takes the largest value of the greatest common divisor that has with another number in the array . Determine the number of subarrays in array whose bitwise "OR" sum is greater than or equal to the number .
A subarray of array is a sequence of elements from different, consecutive positions.
The bitwise "OR" sum of a subarray is defined as , where signifies the bitwise "OR" operator.
Input data
The first line contains the natural numbers and , and the second line contains the natural numbers of the array . The numbers on the same line are separated by a space.
Output data
Print a single number representing the number of subarrays with the desired property.
Constraints and clarifications
# | Points | Constraints |
---|---|---|
1 | 22 | |
2 | 31 | |
3 | 47 | No additional constraints |
Note
Due to the very large input data, use the following instructions at the beginning of the main()
function in your C++ program:
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
Example
stdin
5 3
17 2 9 12 2
stdout
12
Explanation
After each number () takes the largest value of the greatest common divisor that has with another number in array , the array has values . In this new array, there are subarrays that have a bitwise "OR" sum greater than or equal to .