Language: C++

#include "bits/stdc++.h"
using namespace std;
using ld = long double;
ld eps = -1e11;
vector<complex<ld>>quad_equa(complex<ld>a,complex<ld>b,complex<ld>c) {
	auto root = b*b - 4.0l * a*c;
	auto D = sqrt(root);
	
	auto ans = - b / (2.0l * a);
	vector<complex<ld>>anss(2);
	anss[0] = (-b + D) / (2.0l*a);
	anss[1] = (-b - D) / (2.0l*a);
	return anss;
	
}

//f(x) = a0xn + a1xn - 1 + ??\??\??\ + an - 1x + an = 0
void beast(const vector<ld>as,vector<complex<ld>>&ans) {

	const int N = as.size()-1;
	if (N==1) {
		ans.push_back(-as[1] / as[0]);
		return;
	}
	else if (N==2) {
		auto aa= quad_equa(as[0], as[1], as[2]);
		ans.insert(ans.end(), aa.begin(), aa.end());
		return;
	}
	else {

		int k = 1;
		vector<ld>ps, qs;
		ps.push_back(3.52462);
		qs.push_back(-5.32562);
		const ld epsir = 1e-8;
		while (true) {
			
			vector<ld>bs(N+1);
			bs[0] = as[0];
			bs[1] = as[1] - ps[k - 1]*bs[0];
			for (int i = 2; i <=N; ++i) {
				bs[i] = as[i] - ps[k - 1] * bs[i - 1] - qs[k - 1] * bs[i - 2];
				
			}
			vector<ld>cs(as.size());
			cs[0] = bs[0];
			cs[1] = bs[1] - ps[k - 1] * cs[0];
			for (int i = 2; i <=N; ++i) {
				cs[i] = bs[i] - ps[k - 1] * cs[i - 1] - qs[k - 1] * cs[i - 2];
			}

			auto D = powl(cs[N - 2], 2) - cs[N - 3]*(cs[N - 1] - bs[N - 1]);
			auto deltap = (bs[N - 1] * cs[N - 2] - bs[N] * cs[N - 3]) / D;
			auto deltaq = (bs[N] * cs[N - 2] - bs[N - 1] * (cs[N - 1] - bs[N - 1])) / D;

			if (k==1e5||abs(deltap) < epsir&&abs(deltaq) < epsir) {
				auto aaa = quad_equa(1, ps[k - 1], qs[k - 2]);
				ans.insert(ans.end(), aaa.begin(), aaa.end());
				 beast(vector<ld>(bs.begin(), bs.end() - 2),ans);
				return;
			}
			else {
				ps.push_back( ps[k-1] + deltap);
				qs.push_back( qs[k-1] + deltaq);
				k++;
			}
		}
		
	}
	assert(false);
	return;
}
int main() {
	int N; cin >> N;
	vector<ld>as(N + 1);
	for (int i = 0; i < N + 1; ++i) {
		cin >> as[i];
	}
	reverse(as.begin(), as.end());
	vector<complex<ld>>ans; 
	beast(as, ans);
	{
		vector<complex<ld>>bb;
		for (auto aa : ans) {
			ld re(aa.real());
			ld im(aa.imag());
			re = abs(re);
			im = abs(im);
			re += 1e-5;
			im += 1e-5;
			if (abs(re - ld(int(re))) < 1e-4&&abs(im - ld(int(im))) < 1e-4) {
				bb.push_back(aa);
			}
			
		}
		aa = bb;
	}
	vector<pair<int, int>>outputs;
	for (int i = 0; i < ans.size();++i){
		auto aa(ans[i]);
		int re = int(round(aa.real()));
		int im = int(round(aa.imag()));

		outputs.emplace_back(re, im);
	}
	sort(outputs.begin(), outputs.end());
	outputs.erase(unique(outputs.begin(), outputs.end()), outputs.end());
	cout << outputs.size() << endl;
	for (int i = 0; i < outputs.size(); ++i) {
		auto aa(outputs[i]);
		if (aa.first) {
			if (aa.second == 1) {
				cout << aa.first << "+i";
			}
			else if (aa.second == -1) {
				cout << aa.first << "-i";
			}
			else if (aa.second > 0) {
				cout << aa.first << "+" << aa.second << "i";
			}
			else if(aa.second==0){
				cout << aa.first;

			}
			else {
				cout << aa.first << aa.second << "i";
			}
		}
		else {
			if (aa.second == 1) {
				cout << "i";
			}
			else if (aa.second == -1) {
				cout <<  "-i";
			}else if (aa.second == 0) {
				cout << 0;
			}
			else {
				cout << aa.second << "i";
			}
		}
		if (i == outputs.size() - 1)cout << endl;
		else cout << " ";
	}
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:97:17: error: 'aa' was not declared in this scope; did you mean 'as'?
   97 |                 aa = bb;
      |                 ^~
      |                 as