#SP0000227. Cải thiện độ đẹp của dãy (Upgrading Array)
Bài tập thuộc lộ trình
Mục lục đề ⌄
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 positive integers and a strictly increasing list of bad prime numbers . Every other prime is good.
Define . For , factorize into primes, counting multiplicity: each occurrence of a good prime contributes , and each occurrence of a bad prime contributes . The beauty of the array is , and it may be negative.
You may perform any number of operations. Choose , calculate and simultaneously divide each of by . All divisions are exact. Elements with index greater than are unchanged.
Find the maximum possible beauty after zero or more operations.
Input
The first line contains . The second line contains exactly positive integers . The third line contains exactly bad primes in strictly increasing order.
Output
Print one integer: the maximum attainable beauty, which may be negative.
Subtasks
-
Subtask 1 (20 points): ; for every ; ; each is prime.
-
Subtask 2 (30 points): ; for every ; ; each is prime.
-
Subtask 3 (50 points): ; for every ; ; each is prime.
Examples
Input
5 2
4 20 34 10 10
2 5
Output
-2
Explanation
The bad primes are and . Initially the scores of are , totaling . Choose : the prefix gcd is , giving , whose beauty is . Then choose : the prefix gcd is , giving and beauty . Further prefix divisions cannot improve upon .