F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Problem I. Random Sequence

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 1090    Accepted Submission(s): 351


Problem Description
There is a positive integer sequence $a_1,a_2,...,a_n$ with some unknown positions, denoted by 0. Little Q will replace each 0 by a random integer within the range $[1,m]$ equiprobably. After that, he will calculate the value of this sequence using the following formula :
\begin{eqnarray*}
\prod_{i=1}^{n-3} v[\gcd(a_i,a_{i+1},a_{i+2},a_{i+3})]
\end{eqnarray*}
Little Q is wondering what is the expected value of this sequence. Please write a program to calculate the expected value.
 

Input
The first line of the input contains an integer $T(1\leq T\leq10)$, denoting the number of test cases.
In each test case, there are $2$ integers $n,m(4\leq n\leq 100,1\leq m\leq 100)$ in the first line, denoting the length of the sequence and the bound of each number.
In the second line, there are $n$ integers $a_1,a_2,...,a_n(0\leq a_i\leq m)$, denoting the sequence.
In the third line, there are $m$ integers $v_1,v_2,...v_m(1\leq v_i\leq 10^9)$, denoting the array $v$.
 

Output
For each test case, print a single line containing an integer, denoting the expected value. If the answer is $\frac{A}{B}$, please print $C(0\leq C<10^9+7)$ where $A\equiv C\times B\pmod{10^9+7}$.
 

Sample Input
2 6 8 4 8 8 4 6 5 10 20 30 40 50 60 70 80 4 3 0 0 0 0 3 2 4
 

Sample Output
8000 3
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 07:18:17, Gzip enabled