Under construction

Still being built. Things may change

A Math Problem

Time limit1sMemory limit512 MB

Summary
Given sequences a and b, count the pairs of sequences c and d whose LCM matrix equals the matrix of lcm(a_i, b_j), modulo 1e9+7.
Level

Medium7 of 10

Topics
Number theory, Math, Combinatorics
Solved
No attempts yet

Problem

Zenyk is given a sequence of nn integers a1,…,ana_1, \ldots, a_n and a sequence of mm integers b1,…,bmb_1, \ldots, b_m. Both sequences contain only positive integers. You built a matrix of size n×mn \times m such that the element in the ii-th row and the jj-th column is the LCM (least common multiple) of aia_i and bjb_j.

Now he wants to know how many pairs of sequences cc and dd produce the same matrix.

Input

The first line contains two integers nn and mm (1≤n,m≤1051 \le n, m \le 10^5). The second line contains nn integers a1,…,ana_1, \ldots, a_n. The third line contains mm integers b1,…,bmb_1, \ldots, b_m (1≤ai,bj≤1091 \le a_i, b_j \le 10^9).

Output

Print the number of pairs modulo 109+710^9 + 7.

Examples1

  1. Example 1

    Input
    2 3
    2 10
    28 3 4
    
    Expected output
    5