Problem:
Score : 400 points

Problem Statement

Given are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.

Let a semi-common multiple of A be a positive integer X that satisfies the following condition for every k (1 \leq k \leq N):

There exists a non-negative integer p such that X= a_k \times (p+0.5).

Find the number of semi-common multiples of A among the integers between 1 and M (inclusive).

Constraints

1 \leq N \leq 10^5

1 \leq M \leq 10^9

2 \leq a_i \leq 10^9

a_i is an even number.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M
a_1 a_2 ... a_N

Output

Print the number of semi-common multiples of A among the integers between 1 and M (inclusive).

Sample Input 1

2 50
6 10

Sample Output 1

2

15 = 6 \times 2.5

15 = 10 \times 1.5

45 = 6 \times 7.5

45 = 10 \times 4.5

Thus, 15 and 45 are semi-common multiples of A. There are no other semi-common multiples of A between 1 and 50, so the answer is 2.

Sample Input 2

3 100
14 22 40

Sample Output 2

0

The answer can be 0.

Sample Input 3

5 1000000000
6 6 2 6 2

Sample Output 3

166666667

Solution in C# (.NET Core 3.1.201) (judge verdict: Accepted)

using System;
using System.IO;
//x=ai*(p+0.5) aiは偶数なので ai=2ai'とすると 
//x=ai' * (2p+1) つまり入力を2で割ったものに、(2p+1)奇数をかけることになる f(x)=xを何回2で割り切れるか、とすると
//f(x)=f(ai')
//したがってこの問題の条件は
//・aiが偶数
//・全てのiについてf(ai')が同じ
//まとめると(x/2^n)=(ai'/2^n)*(2p+1)のうちそれぞれが奇数になる
//これを　x'=ai''*(2p+1) とすると
//lcm(ai'')=L←奇数 最小公倍数とすると
//x'=L*奇数の組
//その奇数の組を2Lでわって切り上げ

namespace D
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] In = Console.ReadLine().Split(' ');
            int n = int.Parse(In[0]);
            int m = int.Parse(In[1]);
            string[] In2 = Console.ReadLine().Split(' ');
            var A = new int[n];
            for(int i=0; i < n; i++)
            {
                A[i] = int.Parse(In2[i]);
            }
            //a->a'
            for (int i = 0; i < n; i++)
            {
                A[i]/=2;
            }
            //a'->a''
            int t = F(A[0]);
            bool CanDivedeSameTimes = true;
            for(int i=0; i < n; i++)
            {
                if (F(A[i]) != t) CanDivedeSameTimes = false;
                A[i] >>= t;//A[i]/=2^t;
            }
            if (CanDivedeSameTimes)
            {
                m >>= t;
                long l = 1;
                bool IsOverFlow = false;
                for(int i = 0; i < n; i++)
                {
                    l = Lcm(l, A[i]);
                    if (l > m) { IsOverFlow = true; }
                }
                if (IsOverFlow) Console.WriteLine(0);
                else
                {
                    m /= (int)l;
                    int ans = (m + 1) / 2;
                    Console.WriteLine(ans);
                }
            }
            else
            {
                Console.WriteLine(0);
            }
        }
        static int F(int x)
        {//2で何回われるか
            int res = 0;
            while (x % 2 == 0)
            {
                x /= 2;
                res++;
            }
            return res;
        }
        static long Gcd(long a,  long b)
        {
            if (b == 0) return a;
            return Gcd(b,a%b);
        }
        static long Lcm(long a,long b)
        {
            return a / Gcd(a, b) * b;
        }
    }
}