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