3510.GCD Table

Time Limit: 1s Memory Limit: 256MB

Consider a table G of size n \times m such that G(i,j)=GCD(i,j) for all 1 \le i \le n,1 \le j \le m. GCD(a,b) is the greatest common divisor of numbers a and b.

You have a sequence of positive integer numbers a1,a2,...,ak. We say that this sequence occurs in table G if it coincides with consecutive elements in some row, starting from some position. More formally, such numbers 1 \le i \le n and 1 \le j \le m-k+1 should exist that G(i,j+l-1)=al for all 1 \le l \le k.

Determine if the sequence a occurs in table G.

Input Format(From the terminal/stdin)

The first line contains three space-separated integers n, m and k (1 \le n,m \le 1012; 1 \le k \le 10000). The second line contains k space-separated integers a1,a2,...,ak (1 \le ai \le 1012).

Output Format(To the terminal/stdout)

Print a single word "YES", if the given sequence occurs in table G, otherwise print "NO".

Sample Input 1

Copy
100 100 5
5 2 1 2 1
   ·   · \n
 · · · · \n

Sample Output 1

Copy
YES
   \n

Sample Input 2

Copy
100 8 5
5 2 1 2 1
   · · \n
 · · · · \n

Sample Output 2

Copy
NO
  \n

Sample Input 3

Copy
100 100 7
1 2 3 4 5 6 7
   ·   · \n
 · · · · · · \n

Sample Output 3

Copy
NO
  \n

Hints

Sample 1. The tenth row of table G starts from sequence {1, 2, 1, 2, 5, 2, 1, 2, 1, 10}. As you can see, elements from fifth to ninth coincide with sequence a.

Sample 2. This time the width of table G equals 8. Sequence a doesn't occur there.

Submit

请先 登录

© 2025 FAQs