编程介的小学生 2017-06-05 04:50 采纳率: 20.5%
浏览 734
已采纳

Hiiragi's Sticks

Hiiragi likes collecting sticks. It is said that she has collected m short sticks. One day, she was very excited that she found more sticks from a box under her bed. These new sticks have n different lengths, while for each length, there are infinite sticks of the same length.

Hiiragi then came up with an idea, that concatenates the new sticks in different ways to form long sticks of all possible lengths no longer than L. Let's name the lengths a set S. Her mother told her that "Use each of your m short sticks to measure each of the lengths in S. When you find a short sticks being able to measure a length in integer times, get the times it takes and denote it as t. I will give you one candy if you can find one way that uses the following rules to reduce t to 1."
For a number t, find one of its prime factor p, calculate t1 = t / p.
Use t1 as the new t and go back to the first step until t reaches 1.
Note: With the same short stick and the same length in S, two ways are considered to be different iff the reduce processes are not all the same. But it may be counted many times if it's another short stick or the length differs.
So here, you are required to calculate how many candies Hiiragi can get at most.

Input

The first line is T ( ≤ 10), the number of test cases.
Next is T test cases. Each case contains 3 lines. The first line contains three integers n, m, L (n ≤ 20, m ≤ 105, L ≤ 106). The second line is n integers indicating the lengths of each kind of sticks found under the bed. The third line is m integers indicating the sticks Hiiragi originally had. All sticks have length no shorter than 1 and no longer than L.

Output

For each case, print one integer, the number of candies Hiiragi can get at most.

Sample Input

1
2 4 12
4 6
1 3 4 3
Sample Output

16
Hint

In the sample, using sticks of length 4 and 6 can make long sticks of S = {4, 6, 8, 10, 12}.
So, with short stick of length 1, Hiiragi can use the following ways
4 -> 2 -> 1
6 -> 3 -> 1
6 -> 2 -> 1
8 -> 4 -> 2 -> 1
10 -> 5 -> 1
10 -> 2 -> 1
12 -> 6 -> 3 -> 1
12 -> 6 -> 2 -> 1
12 -> 4 -> 2 -> 1
to get 9 candies. Also, with short sticks of length 3, 4 and 3 she can get 2, 3 and 2 candies each. So all she can get is 9 + 2 + 3 + 2 = 16 candies.

  • 写回答

2条回答 默认 最新

  • threenewbee 2017-06-05 17:01
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改