#620. gcd2
gcd2
Description
给定三个排列 , 次询问一个 ,求 。
对于 ,若排列 中第 个元素之后不存在满足 的 (),则 。 反之 的值为排列 中第 个元素之后不存在满足 的 。
对于 ,。
其中 $[a\mid b]=\begin{cases}1&& a\mid b\\0 && a\nmid b\end{cases}$, 表示 是 倍数, 表示 不是 的倍数。
长度为 的排列是一个由 个不同整数组成的数组,这些整数从 到 以任意顺序排列。
Format
Input
Two integers x and y, satisfying .
Output
One integer, the sum of x and y.
Samples
123 500
623
Limitation
1s, 1024KiB for each test case.