PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GL0000377. Dãy con có GCD và LCM xác định (GCD and LCM Subsequences)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Dãy con có GCD và LCM xác định (GCD and LCM Subsequences)

GCD and LCM Subsequences

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Given an array A1,A2,…,ANA_1,A_2,\ldots,A_N of positive integers and two target integers G,LG,L, count the non-empty subsequences satisfying

$$\gcd(\text{selected elements})=G,\qquad \operatorname{lcm}(\text{selected elements})=L.$$

A subsequence selects a subset of positions while keeping their original order. Different index subsets count as different subsequences even if values are repeated. The empty subsequence does not count.

The input does not guarantee G∣LG\mid L; print 00 if the targets cannot be met. Report the count modulo 998244353998244353.

Input

The first line contains NN. The second line contains the NN values AiA_i. The third line contains G,LG,L.

Output

Print the number of valid non-empty subsequences modulo 998244353998244353.

Subtasks

  • Subtask 1 (20 points): 1≤N≤121\le N\le12, 1≤Ai,G,L≤1061\le A_i,G,L\le10^6.

  • Subtask 2 (30 points): 1≤N≤10 0001\le N\le10\,000, 1≤Ai,G,L≤1081\le A_i,G,L\le10^8.

  • Subtask 3 (50 points): 1≤N≤500 0001\le N\le500\,000, 1≤Ai,G,L≤10121\le A_i,G,L\le10^{12}.

Examples

Example 1

Input

5
50 4 50 4 100
2 100

Output

18

Explanation

Choose at least one 5050 and at least one 44. Without a 5050, every selected value is divisible by 44. Without a 44, every selected value is divisible by 5050. A 5050 and a 44 already give GCD 22 and LCM 100100. There are three nonempty choices in each group of two positions, while 100100 is optional, giving 3⋅3⋅2=183\cdot3\cdot2=18.

Example 2

Input

5
8 2 2 1 2
1 8

Output

8

Explanation

To attain LCM 88, select the element 88; to attain GCD 11, select the element 11. Each of the three positions containing 22 may be independently selected or skipped, giving 23=82^3=8 subsequences.

Example 3

Input

4
2 4 8 16
2 16

Output

4

Explanation

Both 22 and 1616 must be included. The elements 44 and 88 can each be included or skipped, resulting in 22=42^2=4.