Row GCD
G. Row GCD
You are given two positive integer sequences a 1 , … , a n a_1, \ldots, a_n a1,…,an and b 1 , … , b m b_1, \ldots, b_m b1,…,bm. For each j = 1 , … , m j = 1, \ldots, m j=1,…,m find the greatest common divisor of a 1 + b j , … , a n + b j a_1 + b_j, \ldots, a_n + b_j a1+bj,…,an+bj.
Input
The first line contains two integers n n n and m m m ( 1 ≤ n , m ≤ 2 ⋅ 1 0 5 1 \leq n, m \leq 2 \cdot 10^5 1≤n,m≤2⋅105).
The second line contains n n n integers a 1 , … , a n a_1, \ldots, a_n a1,…,an ( 1 ≤ a i ≤ 1 0 18 ) 1 \leq a_i \leq 10^{18}) 1≤ai≤1018).
The third line contains m m m integers b 1 , … , b m b_1, \ldots, b_m b1,…,bm ( 1 ≤ b j ≤ 1 0 18 ) 1 \leq b_j \leq 10^{18}) 1≤bj≤1018).
Output
Print m m m integers. The j j j-th of them should be equal to GCD ( a 1 + b j , … , a n + b j ) (a_1 + b_j, \ldots, a_n + b_j) (a1+bj,…,an+bj).
Example
Input
4 4
1 25 121 169
1 2 7 23
Output
2 3 8 24
code
#include<bits/stdc++.h>
#define int long long
#define endl '\n'using namespace std;const int N = 2e5+10,INF=0x3f3f3f3f,mod=1e9+7;typedef pair<int,int> PII;int T=1;void solve(){int n,m,k;cin>>n>>m>>k; int t=0;vector<int> a(n+5,0);vector<int> b(m+5,0);for(int i=1;i<n;i++){cin>>a[i];t=__gcd(t,abs(a[i]-k));}for(int i=0;i<m;i++){cin>>b[i];cout<<__gcd(t,k+b[i])<<" ";}
}signed main(){
// cin>>T; while(T--){solve();}return 0;
}