Language: C++

 /*
ЗАПУСКАЕМ 
░ГУСЯ░▄▀▀▀▄░РАБОТЯГУ░░
▄███▀░◐░░░▌░░░░░░░
░░░░▌░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░▄▀▒▒▀▀▀▀▄
░░░▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
░░░▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░░░▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░▄▄▌▌▄▌▌░░░░░ 
 */
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>


using namespace std;
template<typename T1, typename T2> inline void chkmin(T1 &a, T2 b) {if (a > b) a = b;}
template<typename T1, typename T2> inline void chkmax(T1 &a, T2 b) {if (a < b) a = b;}
#define files(FILENAME) read(FILENAME); write(FILENAME)
#define read(FILENAME) freopen((FILENAME + ".in").c_str(), "r", stdin)
#define write(FILENAME) freopen((FILENAME + ".out").c_str(), "w", stdout)
#define all(c) (c).begin(), (c).end()
#define sz(c) (int)(c).size()
#define left left228
#define right right228
#define y1 y1228
#define mp make_pair
#define pb push_back
#define y2 y2228
#define rank rank228
const string FILENAME = "input";
const int MAXN = 10228;

int n;
int a[MAXN];
bool bad[MAXN];
int g[MAXN];


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
 	//read(FILENAME);
	cin >> n;
	long long kek = 0;
	for (int i = 0; i <= n; i++) {
		cin >> a[i];
		kek += a[i];
	}
	kek = abs(kek);
	if (kek == 0) {
		if (a[0] != 0) {
			kek = abs(a[0]);
		} else {
			for (int cur = 1; ; cur++) {
			long long g = 1;
			for (int i = 0; i <= n; i++) {
				kek += g * a[i];
				g *= cur;
			}
			if (kek != 0) {
				kek = abs(kek);
				break;
			}
			}
		}
	}
	vector<long long> st;
	for (int j = 2; j <= 10003; j++) {
		if (!bad[j]) {
			st.pb(j);
			for (int k = j * j; k <= 10003; k+= j) {
				bad[k] = true;
			}
		}
	}
	long long cur = 2;
	while (cur * cur <= kek) {
		if (kek % cur == 0) {
			while (kek % cur == 0) {
				kek /= cur;
			}
			if (cur > 10003) {
				st.pb(cur);
			}
		}
		cur++;
	}
	if (kek != 1) {
		if (kek > 10003) {
			st.pb(kek);
		}
	}
	sort(all(st));
	st.resize(distance(st.begin(), unique(all(st))));
	for (auto x: st) {
		//cout << x << endl;
		memset(g, 0, sizeof(g));
		for (int i = 0; i <= n; i++) {
			int f = a[i] % x;
			g[i % (x - 1)] += f;
			g[i % (x - 1)] %= x;
		} 
		bool bad = false;
		int sum = 0;
		for (int i = 0; i <= n; i++) {
			sum += g[i];
			sum %= x;
		}
		for (int i = 0; i <= n; i++) {
			if (g[i] != 0) {
				bad = true;
				break;
			}
		}
		if (!bad) {
			cout << x << '\n';
		} else {
			if (sum == 0 && g[0] == 0) {
				bad = false;
				for (int i = 1; i <= x - 1; i++) {
					int cur = 1;
					for (int j = 0; j <= min(n, x - 2); j++) {
						sum += (1LL * cur * g[j]) % x;
						sum %= x;
						cur = (1LL * cur * i) % x;	
					}
					if (sum != 0) {
						bad = true;
						break;
					}
				}
				if (!bad) {
					cout << x << '\n';
				}
			}
		}
	}
	return 0; 	
}

Compiler output:
a.cc: In function 'int main()':
a.cc:156:65: error: no matching function for call to 'min(int&, long long int)'
  156 |                                         for (int j = 0; j <= min(n, x - 2); j++) {
      |                                                              ~~~^~~~~~~~~~
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:24:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:156:65: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
  156 |                                         for (int j = 0; j <= min(n, x - 2); j++) {
      |                                                              ~~~^~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:28:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:156:65: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
  156 |                                         for (int j = 0; j <= min(n, x - 2); j++) {
      |                                                              ~~~^~~~~~~~~~