D. GCD Table
time limit per test
memory limit per test
input
output
Consider a table G of size n × m such that G(i, j) = GCD(i, j) for all1 ≤ i ≤ n, 1 ≤ j ≤ m.GCD(a, b) is the greatest common divisor of numbersa andb.
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 numbers1 ≤ i ≤ n and1 ≤ j ≤ m - k + 1 should exist thatG(i, j + l - 1) = al for all1 ≤ l ≤ k.
Determine if the sequence a occurs in tableG.
Input
The first line contains three space-separated integers n, m and k (1 ≤ n, m ≤ 1012;1 ≤ k ≤ 10000). The second line containsk space-separated integers a1, a2, ..., ak (1 ≤ ai ≤ 1012).
Output
Print a single word "YES", if the given sequence occurs in tableG, otherwise print "NO".
Examples
Input
100 100 5 5 2 1 2 1
Output
YES
Input
100 8 5 5 2 1 2 1
Output
NO
Input
100 100 7 1 2 3 4 5 6 7
Output
NO
Note
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 sequencea.
Sample 2. This time the width of table G equals 8. Sequencea
【分析】
扩展中国剩余定理。
¡ 转化问题:
¡ gcd(x,y)=a0, gcd(x,y+1)=a1, gcd(x,y+2)=a2……
¡ → y=-k(modak) 是原式有解的必要条件
¡ 代入 验证,若原始条件成立则 x,y 由中国 剩 余 定理可得 x=lcm({ ak }) , y 有唯一解
¡ 即 为答案,否则问题无解。
¡ 易知 x 最小为 lcm({ak}) ,在此时根据中国剩余定理 y 有唯一解,但是这个解只保证了 ak|x,y ,并没有保证 ak=gcd(x,y) ,由于随着 x,y 增大若干倍会更加不满足,所以此时是最有可能有解的情况,代入验证即可。
【代码】