We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
long long gcd(long long a, long long b)
{
if(a < 0){
a = -a;
}
if(b < 0){
b = -b;
}
if(b>0){
return gcd(b, a % b);
}
else{
return a;
}
}
int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
int n, q;
cin >> n;
cin>> q;
long long int x;
for(int i = 0; i < n; ++i) {
cin >> x;
arr[i] = x;
}
long long int d = 0;
for(int i = 0; i < n; ++i)
d = gcd(d, arr[i] - arr[0]);
while(q>0)
{
int k; cin >> k;
cout << gcd(d, arr[0] + k) << '\n';
q--;
}
return 0;
}
return 0;
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Salary Blues
You are viewing a single comment's thread. Return to all comments →
// C++ 20........solution
const int N = 100000; long long arr[N];
long long gcd(long long a, long long b) { if(a < 0){ a = -a; }
}
int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */
}