Codeforces Round 534 (Div. 1)
D
Professional layer
Codeforces
3100
原题
← CE →
翻译中…

Cardbluff is popular sport game in Telegram. Each Cardbluff player has ever dreamed about entrance in the professional layer. There are $n$ judges now in the layer and you are trying to pass the entrance exam. You have a number $k$ — your skill in Cardbluff.

翻译中…

Each judge has a number $a_i$ — an indicator of uncertainty about your entrance to the professional layer and a number $e_i$ — an experience playing Cardbluff. To pass the exam you need to convince all judges by playing with them. You can play only one game with each judge. As a result of a particular game, you can divide the uncertainty of $i$-th judge by any natural divisor of $a_i$ which is at most $k$. If GCD of all indicators is equal to $1$, you will enter to the professional layer and become a judge.

翻译中…

Also, you want to minimize the total amount of spent time. So, if you play with $x$ judges with total experience $y$ you will spend $x \cdot y$ seconds.

翻译中…

Print minimal time to enter to the professional layer or $-1$ if it's impossible.

翻译中…

Input

翻译中…

There are two numbers in the first line $n$ and $k$ ($1 \leq n \leq 10^6$, $1 \leq k \leq 10^{12}$) — the number of judges and your skill in Cardbluff.

翻译中…

The second line contains $n$ integers, where $i$-th number $a_i$ ($1 \leq a_i \leq 10^{12}$) — the uncertainty of $i$-th judge

翻译中…

The third line contains $n$ integers in the same format ($1 \leq e_i \leq 10^9$), $e_i$ — the experience of $i$-th judge.

翻译中…

Output

翻译中…

Print the single integer — minimal number of seconds to pass exam, or $-1$ if it's impossible

翻译中…

样例

Input #1
3 6
30 30 30
100 4 5
Output #1
18
InputCopy OutputCopy
Input #2
1 1000000
1
100
Output #2
0
InputCopy OutputCopy
Input #3
3 5
7 7 7
1 1 1
Output #3
-1
InputCopy OutputCopy
题目信息
题号
1103D
时间限制
3 s
内存限制
512 MB
标签
位运算
动态规划

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。