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 Rust (1.15.1) (judge verdict: Wrong Answer)

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

use std::collections::HashSet;

fn primes_table(n: usize) -> Vec<bool> {
    let mut result = vec![true; n - 1]; // i -> i - 2
    let n_upper = (n as f64).sqrt() as usize;

    for i in 2..n_upper + 1 {
        if !result[i - 2] {
            continue;
        }

        for j in 2..((n / i) + 1) {
            result[j * i - 2] = false;
        }
    }

    result
}

fn factorize(mut n: usize, primes: &[usize]) -> Vec<(usize, usize)> {
    let mut result = vec![];

    for &prime in primes.iter() {
        let mut count = 0;
        while n % prime == 0 {
            count += 1;
            n /= prime;
        }

        if count != 0 {
            result.push((prime, count));
        }
    }

    if n != 1 {
        result.push((n, 1));
    }

    result
}

use std::collections::HashMap;

fn common(as_: &[usize]) -> usize {
    let prime_table = primes_table(as_[as_.len() - 1] + 1);
    let primes = prime_table
        .iter()
        .enumerate()
        .filter(|&(_, &f)| f)
        .map(|(i, _)| i + 2)
        .collect::<Vec<_>>();
    let mut map = HashMap::new();
    for fs in as_.iter().map(|&a| factorize(a, &primes)) {
        for (p, n) in fs.into_iter() {
            if map.contains_key(&p) {
                let temp = map[&p];
                map.insert(p, std::cmp::max(temp, n));
            } else {
                map.insert(p, n);
            }
        }
    }

    map.into_iter().map(|(p, n)| p.pow(n as _)).product()
}

fn main() {
    input! {
        n: usize,
        m: usize,
        as_: [usize; n]
    }

    let as_: HashSet<_> = as_.into_iter().collect();
    let mut as_: Vec<_> = as_.into_iter().collect();
    let n = as_.len();
    as_.sort();
    let a_common = common(&as_);
    let a_halves: Vec<_> = as_.iter().map(|&a| a / 2).collect();

    let base = m / a_common;

    if m % a_common >= a_common / 2 {
        println!("{}", base + 1);
    } else {
        println!("{}", base)
    }
}