#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <numeric>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

// vector<ll> prime_factor(ll n) {
//     vector<ll> ret;
//     if(n != 1) ret.push_back(1);
//     for(ll i = 1; i*i < n; i++) {
//         if(n % i == 0) {
//             ret.push_back(n/i);
//         }
//     }
//     ret.push_back(n);

//     return ret;
// }

template<typename T>
vector<T> prime_factor(T n)
{
    vector<T> result;

    T boundary = sqrt(n);

    for (T i = 1; i <= boundary; i++) {
        if (n % i == 0) {
            result.push_back(i);
            if(i != (n / i) && i * i != n)
                result.push_back(n/i);
        }
    }
    sort(result.begin(),result.end());
    return result;
}

struct mod {
    ll plus_mod;
    ll minus_mod;
    mod(ll input_plus_mod, ll input_minus_mod)
    {
        plus_mod = input_plus_mod;
        minus_mod = input_minus_mod;
    }
};

bool cmp_plus_mod(const mod &a, const mod &b)
{
    return a.plus_mod < b.plus_mod;
}

bool cmp_minus_mod(const mod &a, const mod &b)
{
    return a.minus_mod < b.minus_mod;
}

int main() {
    int n;
    ll k;
    cin >> n >> k;
    vector<ll> a(n);
    for(int i=0; i<n; i++) cin >> a[i];
    int sum = accumulate(a.begin(), a.end(), 0);

    vector<ll> factors = prime_factor<ll>(sum);
    reverse(factors.begin(), factors.end());

    ll ans;
    for(auto x: factors) {
        // cout << "factor: " << x << endl;
        vector<ll> plus_mod, minus_mod;
        vector<mod> mod_list;
        ll counter = k;
        for(int i=0; i<n; i++){
            if(a[i]%x!=0) {
                mod p = {a[i]%x, x - a[i]%x};
                mod_list.push_back(p);
            }
        }
        
        // cout << "start while loop" << endl;

        while(!mod_list.empty() && counter > 0) {
            // cout << "mod_list.size() = " << mod_list.size() << endl;
            // cout << "mod_list: "; for(auto x: mod_list) cout << x.plus_mod << ", "; cout << endl;
            sort(mod_list.begin(), mod_list.end(), cmp_plus_mod);

            mod head = mod_list[0];
            mod pair = *(mod_list.end() - 1);
            int pair_idx = mod_list.size()-1;
            ll min_value = 2e9;

            ll tmp = min(head.plus_mod, pair.minus_mod);
            // ll tmp = head.plus_mod;
            counter -= tmp;
            // cout << "tmp: "  << tmp << endl;
            // cout << "idx: " << 0 << " pair_idx: " << pair_idx << endl;
            // cout << "head: " << head.plus_mod << ", " << head.minus_mod << endl;
            // cout << "pair: " << pair.plus_mod << ", " << pair.minus_mod << endl;
            if( (head.plus_mod-tmp)%x == 0 || (head.minus_mod+tmp)%x == 0) {
                // cout << "erase head" << endl;
                mod_list.erase(mod_list.begin());
                pair_idx--;
            } else {
                mod_list[0].plus_mod = (head.plus_mod-tmp)%x;
                mod_list[0].minus_mod = (head.minus_mod+tmp)%x;
            }

            if((pair.plus_mod + tmp) % x==0 || (pair.minus_mod - tmp) % x == 0) {
                // cout << "erase pair" << endl;
                mod_list.erase(mod_list.begin()+pair_idx);
            } else {
                mod_list[pair_idx].plus_mod = (pair.plus_mod+tmp)%x;
                mod_list[pair_idx].minus_mod = (pair.minus_mod-tmp)%x;
            }

            // cout << "counter: " << counter << endl;
        }

        // cout << "get answer" << endl;
        if(mod_list.empty() && counter >= 0) {
            ans = x;
            break;
        }

    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256