Source Code
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define fixed(n) cout << fixed << setprecision(n);
#define mod 1000000007
#define cin(v) for (auto&i:v) cin >> i;
#define cout(v) for (auto&i:v) cout << i << " ";
#define ceil(n,m) (n / m + (n%m != 0))
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

void lil_codi_vert(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    #endif
}

//int dx[] = {1, 1, 1, 0, 0, -1, -1, -1};
//int dy[] = {-1, 0, 1, -1, 1, -1, 0, 1};



int main(){
    lil_codi_vert();
    ll n, m; cin >> n >> m;
    ll g = gcd(n,m);
    vector<ll> v(n); cin(v);
    ll sum = 0;
    for(auto&i: v){
        sum += i%g;
        sum %= g;
    }

    if(sum % g == 0) cout << g;
    else cout << 0;

    return 0;
}
Copy
Spin the wheel aboelsoudJr
GNU G++17
143 ms
4.2 MB
Accepted