CF1103D.Professional layer
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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 ai — an indicator of uncertainty about your entrance to the professional layer and a number ei — 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 ai 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⋅y seconds.
Print minimal time to enter to the professional layer or −1 if it's impossible.
输入格式
There are two numbers in the first line n and k ( 1≤n≤106 , 1≤k≤1012 ) — the number of judges and your skill in Cardbluff.
The second line contains n integers, where i -th number ai ( 1≤ai≤1012 ) — the uncertainty of i -th judge
The third line contains n integers in the same format ( 1≤ei≤109 ), ei — the experience of i -th judge.
输出格式
Print the single integer — minimal number of seconds to pass exam, or −1 if it's impossible
输入输出样例
输入#1
3 6 30 30 30 100 4 5
输出#1
18
输入#2
1 1000000 1 100
输出#2
0
输入#3
3 5 7 7 7 1 1 1
输出#3
-1