Source Code
#include<bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")

long long gcd(long long a, long long b){
        if(b == 0)
                return a;
        
        return gcd(b, a % b);
}
int main(){
        cin.tie(0);
        cin.sync_with_stdio(0);
        
        long long n, m;
        cin>>n>>m;
        
        long long sum = 0;
        long long a[n];
        long long g = __gcd(n, m);
        for(int i = 0; i < n; i++){
                cin>>a[i];
                sum += a[i] % g;
                sum %= g;
        }
        
        if(sum == 0){
                cout<<gcd(m, n)<<"\n";
        }else{
                cout<<"0\n";
        }
}
Copy
Spin the wheel maghrabyJr_
GNU G++17
153 ms
4.2 MB
Accepted