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++14 (GCC 5.4.1) (judge verdict: Time Limit Exceeded)

#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>

using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()
// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return;std::cout << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class X> void DEBUG(X d, T e){if(DEBUG_OUT == false)return;std::cout <<d<<" ";DEBUG(e);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//BELOW
//-----CODE------//
map<int, int> ret;
void prime_factor(int n)
{
  // map<int, int> ret;
  for (int i = 2; i * i <= n; i++)
  {
    int COUNT = 0;
    while (n % i == 0)
    {
      COUNT ++;
      n /= i;
    }
    if(ret.find(i) != ret.end())
    ret[i] = max(ret[i],COUNT);
    else
    {
      ret[i] = COUNT;
    }
  }
  if (n != 1)
  {
    if(ret.find(n) != ret.end())
    {
    ret[n] = max(ret[n],1LL);
    }
    else
    {
      ret[n] = 1;
    }
  }
    return;
}

void solve(void)
{
  int N, M;
  cin >> N >> M;
  vector<int> vec(N);

  vector<int> vec2(N);
  for (int i = 0; i < N; i++)
  {
    cin >> vec[i];
    vec[i] /= 2;
    int A = vec[i];
    while(A%2 == 0)
    {
      vec2[i]++;
      A /=2;
    }
  }

  for (int i = 0; i < N-1; i++)
  {
    if(vec2[i] != vec2[i+1])
    {
      cout<<0<<endl;
      return;
    }
  }
  
  
  // DEBUG(vec);
  // prime_factor(vec[0]);
  bool check = true;

  for (int i = 0; i < N; i++)
  {
    if(vec[i] == 1)continue;
    prime_factor(vec[i]);

    }
  

  int V_LCM = 1;
  for (int i = 0; i < ret.size(); i++)
  {
    static auto itr = ret.begin();
    V_LCM *= pow(itr->first,itr->second);
    // DEBUG(itr->first,itr->second);
    itr++;
  }
  int ANS = M/V_LCM - M/V_LCM/2;

  if(check == 0)
  {
    cout<<0<<endl;
  }
  else
  {
    cout<<ANS<<endl;//ANS
  }
  
  return;
}

int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}