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

#SP0000227. Cải thiện độ đẹp của dãy (Upgrading Array)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Cải thiện độ đẹp của dãy (Upgrading Array)

Upgrading Array

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

You are given a sequence of nn positive integers a1,a2,…,ana_1,a_2,\ldots,a_n and a strictly increasing list of mm bad prime numbers b1,b2,…,bmb_1,b_2,\ldots,b_m. Every other prime is good.

Define f(1)=0f(1)=0. For x>1x>1, factorize xx into primes, counting multiplicity: each occurrence of a good prime contributes +1+1, and each occurrence of a bad prime contributes −1-1. The beauty of the array is ∑i=1nf(ai)\sum_{i=1}^n f(a_i), and it may be negative.

You may perform any number of operations. Choose 1≤r≤n1\le r\le n, calculate g=gcd⁡(a1,…,ar)g=\gcd(a_1,\ldots,a_r) and simultaneously divide each of a1,…,ara_1,\ldots,a_r by gg. All divisions are exact. Elements with index greater than rr are unchanged.

Find the maximum possible beauty after zero or more operations.

Input

The first line contains n,mn,m. The second line contains exactly nn positive integers a1,…,ana_1,\ldots,a_n. The third line contains exactly mm bad primes b1,…,bmb_1,\ldots,b_m in strictly increasing order.

Output

Print one integer: the maximum attainable beauty, which may be negative.

Subtasks

  • Subtask 1 (20 points): 1≤n,m≤71\le n,m\le7; 1≤ai≤1091\le a_i\le10^9 for every ii; 2≤b1<⋯<bm≤1092\le b_1<\cdots<b_m\le10^9; each bjb_j is prime.

  • Subtask 2 (30 points): 1≤n,m≤2001\le n,m\le200; 1≤ai≤1091\le a_i\le10^9 for every ii; 2≤b1<⋯<bm≤1092\le b_1<\cdots<b_m\le10^9; each bjb_j is prime.

  • Subtask 3 (50 points): 1≤n,m≤50001\le n,m\le5000; 1≤ai≤1091\le a_i\le10^9 for every ii; 2≤b1<⋯<bm≤1092\le b_1<\cdots<b_m\le10^9; each bjb_j is prime.

Examples

Input

5 2
4 20 34 10 10
2 5

Output

-2

Explanation

The bad primes are 22 and 55. Initially the scores of 4,20,34,10,104,20,34,10,10 are −2,−3,0,−2,−2-2,-3,0,-2,-2, totaling −9-9. Choose r=5r=5: the prefix gcd is 22, giving (2,10,17,5,5)(2,10,17,5,5), whose beauty is −4-4. Then choose r=2r=2: the prefix gcd is 22, giving (1,5,17,5,5)(1,5,17,5,5) and beauty 0−1+1−1−1=−20-1+1-1-1=-2. Further prefix divisions cannot improve upon −2-2.