C Elven Efficiency
题号:NC224726
时间限制:C/C++/Rust/Pascal 5秒,其他语言10秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

Like many creatures featured in programming problems, the animals of the forest love playing games
with stones. They recently came up with a game to teach the younger animals about divisibility. In this
game, each animal starts with a pile of stones. At the start of the game, a series of numbers is called out.
For each number that is called, every animal whose number of stones is divisible by the called number
scores a point. At the end of the game, the animal with the most points wins.

Emma the forest elf has watched the forest animals play this game many times, and has grown tired of
watching the winning animal gloat about how many points they scored. To prevent this from happening,
she plans to meddle in the next game the animals play to ensure that no animal scores any points. She
plans to wait atop a nearby tree, and keep track of how many stones each animal has. Each round, if an
animal is about to score a point, she can toss a stone into that animal's pile, increasing their number of
stones by one. The tossed stone stays in that pile for the rest of the game. Throughout the course of the
game, she may need to toss several stones into the same pile. But stones are heavy, and she wants to
carry as few as possible to the top of her hideout tree. She already knows how many stones each of the
𝒏 animals will start with, as well as the number to be called out in each of the 𝒎 rounds of the game,
but she wants you to calculate the minimum total number of stones she will have to throw to ensure
that no animal scores any points.

输入描述:

The first line of input contains two space-separated integers 𝒏 and 𝒎 (1 ≤ 𝒏, 𝒎 ≤ 105 ), where 𝒏 is the number of animals, and 𝒎 is the number of rounds of the game.

Each of the next 𝒏 lines contain a single integer 𝒂 (1 ≤ 𝒂 ≤ 3 ∙ 105), which are the numbers of stones held by each animal.

Each of the next 𝒎 lines contain a single integer 𝒌 (2 ≤ 𝒌 ≤ 3 ∙ 105 ), which are the numbers called out, in order.

输出描述:

Output a single integer, which is the minimum number of stones that Emma must use to prevent any and all animals from scoring any points.
示例1

输入

复制
3 5 
10 
11 
12 
2 
11 
4 
13 
2

输出

复制
12