GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Sunday 6 November 2022

[Solution] Count GCD Codeforces Solution



D. Count GCD
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given two integers n and m and an array a of n integers. For each 1in it holds that 1aim.

Your task is to count the number of different arrays b of length n such that:

  • 1bim for each 1in, and
  • gcd(b1,b2,b3,...,bi)=ai for each 1in.

Here gcd(a1,a2,,ai) deontes the greatest common divisor (GCD) of integers a1,a2,,ai.

Since this number can be too large, print it modulo 998244353.

Input

Each test consist of multiple test cases. The first line contains a single integer t (1t100) — the number of test cases. The description of test cases follows.

The first line of each test case contains two integers n and m (1n21051m109) — the length of the array a and the maximum possible value of the element.

The second line of each test case contains n integers a1,a2,,an (1aim) — the elements of the array a.

It is guaranteed that the sum of n across all test cases doesn't exceed 2105.

Output

For each test case, print a single integer — the number of different arrays satisfying the conditions above. Since this number can be large, print it modulo 998244353.


Note

In the first test case, the possible arrays b are:

  • [4,2,1];
  • [4,2,3];
  • [4,2,5].

In the second test case, the only array satisfying the demands is [1,1].

In the third test case, it can be proven no such array exists

No comments:

Post a Comment