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# (Mono 4.6.2.0) (judge verdict: Wrong Answer)

using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		const long MOD = 1000000007;

		static void Main(string[] args)
		{
			var cin = new Scanner2();
			int n = cin.Int();
			long m = cin.Long();
			long[] a = cin.ArrayLong(n);
			for (int i = 0; i < n; i++) {
				a[i] /= 2;
			}

			if (n == 1) {
				long count = m / a[0];

				Console.WriteLine(count / 2 - 1);
				return;
			}

			var factors = new Dictionary<long, long>();
			for (int i = 0; i < n; i++) {
				long value = a[i];
				for (long j = 2; j * j <= value; ++j) {
					int cu = 0;
					while (value % j == 0) {
						++cu;
						value /= j;
					}

					if (cu != 0) {
						if (factors.ContainsKey(j)) {
							factors[j] = Math.Max(factors[j], cu);
						} else {
							factors[j] = cu;
						}
					}
				}

				if (value != 1) {
					long j = value;
					if (factors.ContainsKey(j)) {
						factors[j] = Math.Max(factors[j], 1);
					} else {
						factors[j] = 1;
					}
				}
			}

			if (factors.ContainsKey(2) && factors[2] > 1) {
				long first = a[0];
				bool same = true;
				for (int i = 0; i < n; i++) {
					if (first != a[i]) {
						same = false;
						break;
					}
				}

				if (same == false) {
					Console.WriteLine(0);
					return;
				}

				long count = m / first;
				Console.WriteLine((count / 2) - 1);
				return;
			}

			long val = 1;
			foreach (long key in factors.Keys) {
				for (int i = 0; i < factors[key]; i++) {
					val *= key;
					if (val > m) {
						Console.WriteLine(0);
						return;
					}
				}
			}

			long ans = m / val / 2;
			if ((m / val) % 2 == 1) {
				ans++;
			}

			Console.WriteLine(ans);
		}

		public static Dictionary<long, long> GetPrimeFactors(long value)
		{
			var factors = new Dictionary<long, long>();
			for (long i = 2; i * i <= value; ++i) {
				while (value % i == 0) {
					if (factors.ContainsKey(i) == false) {
						factors[i] = 1;
					} else {
						factors[i] += 1;
					}

					value /= i;
				}
			}

			if (value != 1) {
				factors[value] = 1;
			}

			return factors;
		}
	}


	public class Scanner2
	{
		private readonly char[] delimiter_ = new char[] { ' ' };
		private readonly string filePath_;
		private string[] buf_;
		private int index_;
		Func<string> reader_;

		public Scanner2(string file = "")
		{
			if (string.IsNullOrWhiteSpace(file)) {
				reader_ = Console.ReadLine;
			} else {
				filePath_ = file;
				var fs = new StreamReader(file);
				reader_ = fs.ReadLine;
			}
			buf_ = new string[0];
			index_ = 0;
		}

		public string Next()
		{
			if (index_ < buf_.Length) {
				return buf_[index_++];
			}

			string st = reader_();
			while (st == "") {
				st = reader_();
			}

			buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
			if (buf_.Length == 0) {
				return Next();
			}

			index_ = 0;
			return buf_[index_++];
		}

		public int Int() => int.Parse(Next());
		public long Long() => long.Parse(Next());
		public double Double() => double.Parse(Next());

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Int() + add;
			}
			return Array;
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Long() + add;
			}
			return Array;
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Double() + add;
			}
			return Array;
		}

		public void Save(string text)
		{
			if (string.IsNullOrWhiteSpace(filePath_)) {
				return;
			}

			File.WriteAllText(filePath_ + "_output.txt", text);
		}
	}
}