1 solutions

  • 0
    @ 2025-11-27 11:58:50

    C++ :

    #include <bits/stdc++.h>
    using namespace std;
     
    const int maxn=1e5+5;
    int a[maxn];
    int n,q,t;
     
    int gcd(int a,int b) {
        if(b==0) return a;
        return gcd(b,a%b);
    }
     
    int main() {
        scanf("%d%d",&n,&q);
        for(int i=1; i<=n; i++) {
            scanf("%d",&a[i]);
        }
        sort(a+1,a+n+1);
        for(int i=2; i<=n; i++) {
            t=gcd(t,a[i]-a[i-1]);
        }
        for(int i=1; i<=q; i++) {
            printf("%d\n",gcd(t,a[1]+i));
        }
        return 0;
    }
     
    /*
    in:
    5 3
    6 9 12 18 30
    out:
    1
    1
    3
    */
    
    • 1

    Information

    ID
    89
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    (None)
    Tags
    # Submissions
    0
    Accepted
    0
    Uploaded By