Language: C++

#include <iostream>
#include <sstream>
#include <vector>
#include <cassert>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <tuple>
#include <regex>
#include <map>

using namespace std;
using ull = unsigned long long;
using ll = long long;

// もらってきた:
// https://qiita.com/EqualL2/items/0964832dd7929d4004ad
std::vector<bool> IsPrime;

void sieve(size_t max) {
	if (max + 1 > IsPrime.size()) {     // resizeで要素数が減らないように
		IsPrime.resize(max + 1, true); // IsPrimeに必要な要素数を確保
	}
	IsPrime[0] = false; // 0は素数ではない
	IsPrime[1] = false; // 1は素数ではない

	for (size_t i = 2; i*i <= max; ++i) // 0からsqrt(max)まで調べる
		if (IsPrime[i]) // iが素数ならば
			for (size_t j = 2; i*j <= max; ++j) // (max以下の)iの倍数は
				IsPrime[i*j] = false;      // 素数ではない
}

ull gcd(ull a, ull b) {
	return (b == 0) ? a : gcd(b, a%b);
}


bool is_prime(ull num) {
	if (num <= 3) {
		return num > 1;
	} else if (num % 2 == 0 || num % 3 == 0) {
		return false;
	} else {
		for (ull i = 5; i * i <= num; i += 6) {
			if (num % i == 0 || num % (i + 2) == 0) {
				return false;
			}
		}
		return true;
	}
}


int main() {
//	sieve(1000000000);

	// 素数判定の表
	int N;
	cin >> N;

	vector<ull> vec(N);

	for (size_t i = 0; i < N; i++) {
		cin >> vec[i];
	}

	// 全体の最大公約数を計算する


	ull ruisekians = 1;
	do {
		vector<ull> primes;
		for (size_t i = 0; i < vec.size(); i++) {
			if (is_prime(vec[i])) {
				primes.push_back(vec[i]);
			}
		}
		if (primes.size() > 1) {
			cout << 1 << endl;
			return 0;
		} else if (primes.size() == 1) {
			auto it = remove_if(vec.begin(), vec.end(), [primes](auto x) {
				return x == primes[0];
			});
			vec.erase(it, vec.end());
			ull ans = vec[0];
			for (size_t i = 1; i < vec.size(); i++) {
				ans = gcd(ans, vec[i]);
			}
			cout << ruisekians * ans << endl;
			return 0;

		} else {
			// まだ何も消していない場合
			ull ans = vec[0];
			for (size_t i = 1; i < vec.size(); i++) {
				ans = gcd(ans, vec[i]);
			}

			// 全部を割り算してもう一度やりなおし
			for (size_t i = 0; i < vec.size(); i++) {
				vec[i] /= ans;
			}
			ruisekians *= ans;
			auto it = find(cbegin(vec), cend(vec), [ruisekians](auto x) {
				return ruisekians == x;
			});
			if (it != cend(vec)) {
				cout << ruisekians<< endl;
				return 0;
			}
		}
	} while (true);

	return 0;
}

#include <iostream>
#include <sstream>
#include <vector>
#include <cassert>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <tuple>
#include <regex>
#include <map>

using namespace std;
using ull = unsigned long long;
using ll = long long;

// もらってきた:
// https://qiita.com/EqualL2/items/0964832dd7929d4004ad
std::vector<bool> IsPrime;

void sieve(size_t max) {
	if (max + 1 > IsPrime.size()) {     // resizeで要素数が減らないように
		IsPrime.resize(max + 1, true); // IsPrimeに必要な要素数を確保
	}
	IsPrime[0] = false; // 0は素数ではない
	IsPrime[1] = false; // 1は素数ではない

	for (size_t i = 2; i*i <= max; ++i) // 0からsqrt(max)まで調べる
		if (IsPrime[i]) // iが素数ならば
			for (size_t j = 2; i*j <= max; ++j) // (max以下の)iの倍数は
				IsPrime[i*j] = false;      // 素数ではない
}

ull gcd(ull a, ull b) {
	return (b == 0) ? a : gcd(b, a%b);
}


bool is_prime(ull num) {
	if (num <= 3) {
		return num > 1;
	} else if (num % 2 == 0 || num % 3 == 0) {
		return false;
	} else {
		for (ull i = 5; i * i <= num; i += 6) {
			if (num % i == 0 || num % (i + 2) == 0) {
				return false;
			}
		}
		return true;
	}
}


int main() {
//	sieve(1000000000);

	// 素数判定の表
	int N;
	cin >> N;

	vector<ull> vec(N);

	for (size_t i = 0; i < N; i++) {
		cin >> vec[i];
	}

	// 全体の最大公約数を計算する


	ull ruisekians = 1;
	do {
		vector<ull> primes;
		for (size_t i = 0; i < vec.size(); i++) {
			if (is_prime(vec[i])) {
				primes.push_back(vec[i]);
			}
		}
		if (primes.size() > 1) {
			cout << 1 << endl;
			return 0;
		} else if (primes.size() == 1) {
			auto it = remove_if(vec.begin(), vec.end(), [primes](auto x) {
				return x == primes[0];
			});
			vec.erase(it, vec.end());
			ull ans = vec[0];
			for (size_t i = 1; i < vec.size(); i++) {
				ans = gcd(ans, vec[i]);
			}
			cout << ruisekians * ans << endl;
			return 0;

		} else {
			// まだ何も消していない場合
			ull ans = vec[0];
			for (size_t i = 1; i < vec.size(); i++) {
				ans = gcd(ans, vec[i]);
			}

			// 全部を割り算してもう一度やりなおし
			for (size_t i = 0; i < vec.size(); i++) {
				vec[i] /= ans;
			}
			ruisekians *= ans;
			auto it = find(cbegin(vec), cend(vec), [ruisekians](auto x) {
				return ruisekians == x;
			});
			if (it != cend(vec)) {
				cout << ruisekians<< endl;
				return 0;
			}
		}
	} while (true);

	return 0;
}



Compiler output:
a.cc:139:19: error: redefinition of 'std::vector<bool> IsPrime'
  139 | std::vector<bool> IsPrime;
      |                   ^~~~~~~
a.cc:20:19: note: 'std::vector<bool> IsPrime' previously declared here
   20 | std::vector<bool> IsPrime;
      |                   ^~~~~~~
a.cc:141:6: error: redefinition of 'void sieve(size_t)'
  141 | void sieve(size_t max) {
      |      ^~~~~
a.cc:22:6: note: 'void sieve(size_t)' previously defined here
   22 | void sieve(size_t max) {
      |      ^~~~~
a.cc:154:5: error: redefinition of 'ull gcd(ull, ull)'
  154 | ull gcd(ull a, ull b) {
      |     ^~~
a.cc:35:5: note: 'ull gcd(ull, ull)' previously defined here
   35 | ull gcd(ull a, ull b) {
      |     ^~~
a.cc:159:6: error: redefinition of 'bool is_prime(ull)'
  159 | bool is_prime(ull num) {
      |      ^~~~~~~~
a.cc:40:6: note: 'bool is_prime(ull)' previously defined here
   40 | bool is_prime(ull num) {
      |      ^~~~~~~~
a.cc:175:5: error: redefinition of 'int main()'
  175 | int main() {
      |     ^~~~
a.cc:56:5: note: 'int main()' previously defined here
   56 | int main() {
      |     ^~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:71,
                 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:1:
/usr/include/c++/14/bits/predefined_ops.h: In instantiation of 'bool __gnu_cxx::__ops::_Iter_equals_val<_Value>::operator()(_Iterator) [with _Iterator = __gnu_cxx::__normal_iterator<const long long unsigned int*, std::vector<long long unsigned int> >; _Value = const main()::<lambda(auto:2)>]':
/usr/include/c++/14/bits/stl_algobase.h:2107:14:   required from '_RandomAccessIterator std::__find_if(_RandomAccessIterator, _RandomAccessIterator, _Predicate, random_access_iterator_tag) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<const long long unsigned int*, vector<long long unsigned int> >; _Predicate = __gnu_cxx::__ops::_Iter_equals_val<const main()::<lambda(auto:2)> >]'
 2107 |           if (__pred(__first))
      |               ~~~~~~^~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:2152:23:   required from '_Iterator std::__find_if(_Iterator, _Iterator, _Predicate) [with _Iterator = __gnu_cxx::__normal_iterator<const long long unsigned int*, vector<long long unsigned int> >; _Predicate = __gnu_cxx::__ops::_Iter_equals_val<const main()::<lambda(auto:2)> >]'
 2152 |       return __find_if(__first, __last, __pred,
      |              ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
 2153 |                        std::__iterator_category(__first));
      |                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:3850:28:   required from '_IIter std::find(_IIter, _IIter, const _Tp&) [with _IIter = __gnu_cxx::__normal_iterator<const long long unsigned int*, vector<long long unsigned int> >; _Tp = main()::<lambda(auto:2)>]'
 3850 |       return std::__find_if(__first, __last,
      |              ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
 3851 |                             __gnu_cxx::__ops::__iter_equals_val(__val));
      |                             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:107:18:   required from here
  107 |                         auto it = find(cbegin(vec), cend(vec), [ruisekians](auto x) {
      |                                   ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  108 |                                 return ruisekians == x;
      |                                 ~~~~~~~~~~~~~~~~~~~~~~~
  109 |                         });
      |                         ~~             
/usr/include/c++/14/bits/predefined_ops.h:270:24: error: no match for 'operator==' (operand types are 'const long long unsigned int' and 'const main()::<lambda(auto:2)>')
  270 |         { return *__it == _M_value; }
      |                  ~~~~~~^~~~~~~~~~~
In file included from /usr/include/c++/14/string:48:
/usr/include/c++/14/bits/stl_iterator.h:1208:5: note: candidate: 'template<class _IteratorL, class _IteratorR, class _Container> bool __gnu_cxx::operator==(const __normal_iterator<_IteratorL, _Container>&, const __normal_iterator<_IteratorR, _Container>&)'
 1208 |     operator==(const __normal_iterator<_IteratorL, _Container>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1208:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/predefined_ops.h:270:24: note:   mismatched types 'const __gnu_cxx::__normal_iterator<_IteratorL, _Container>' and 'const long long unsigned int'
  270 |         { return *__it == _M_value; }
      |                  ~~~~~~^~~~~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1216:5: note: candidate: 'template<class _Iterator, class _Container> bool __gnu_cxx::operator==(const __normal_iterator<_Iterator, _Container>&, const __normal_iterator<_Iterator, _Container>&)'
 1216 |     operator==(const __normal_iterator<_Iterator, _Container>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1216:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/predefined_ops.h:270:24: note:   mismatched types 'const __gnu_cxx::__normal_iterator<_Iterator, _Container>' and 'const long long unsigned int'
  270 |         { return *__it == _M_value; }
      |                  ~~~~~~^~~~~~~~~~~
/usr/include/c++/14/bits/predefined_ops.h: In instantiation of 'bool __gnu_cxx::__ops::_Iter_equals_val<_Value>::operator()(_Iterator) [with _Iterator = __gnu_cxx::__normal_iterator<const long long unsigned int*, std::vector<long long unsigned int> >; _Value = const main()::<lambda(auto:4)>]':
/usr/include/c++/14/bits/stl_algobase.h:2107:14:   required from '_RandomAccessIterator std::__find_if(_RandomAccessIterator, _RandomAccessIterator, _Predicate, random_access_iterator_tag) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<const long long unsigned int*, vector<long long unsigned int> >; _Predicate = __gnu_cxx::__ops::_Iter_equals_val<const main()::<lambda(auto:4)> >]'
 2107 |           if (__pred(__first))
      |               ~~~~~~^~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:2152:23:   required from '_Iterator std::__find_if(_Iterator, _Iterator, _Predicate) [with _Iterator = __gnu_cxx::__normal_iterator<const long long unsigned int*, vector<long long unsigned int> >; _Predicate = __gnu_cxx::__ops::_Iter_equals_val<const main()::<lambda(auto:4)> >]'
 2152 |       return __find_if(__first, __last, __pred,
      |              ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
 2153 |                        std::__iterator_category(__first));
      |                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:3850:28:   required from '_IIter std::find(_IIter, _IIter, const _Tp&) [with _IIter = __gnu_cxx::__normal_iterator<const long long unsigned int*, vector<long long unsigned int> >; _Tp = main()::<lambda(auto:4)>]'
 3850 |       return std::__find_if(__first, __last,
      |              ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
 3851 |                             __gnu_cxx::__ops::__iter_equals_val(__val));
      |                             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:226:18:   required from here
  226 |                         auto it = find(cbegin(vec), cend(vec), [ruisekians](auto x) {
      |                                   ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  227 |                                 return ruisekians == x;
      |                                 ~~~~~~~~~~~~~~~~~~~~~~~
  228 |                         });
      |                         ~~             
/usr/include/c++/14/bits/predefined_ops.h:270:24: error: no match for 'operator==' (operand types are 'const long long unsigned int' and 'const main()::<lambda(auto:4)>')
  270 |         { return *__it == _M_value; }
      |                  ~~~~~~^~~~~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1208:5: note: candidate: 'template<class _IteratorL, class _IteratorR, class _Container> bool __gnu_cxx::operator==(const __normal_iterator<_IteratorL, _Container>&, const __normal_iterator<_IteratorR, _Container>&)'
 1208 |     operator==(const __normal_iterator<_IteratorL, _Container>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1208:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/predefined_ops.h:270:24: note:   mismatched types 'const __gnu_cxx::__normal_iterator<_IteratorL, _Container>' and 'const long long unsigned int'
  270 |         { return *__it == _M_value; }
      |                  ~~~~~~^~~~~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1216:5: note: candidate: 'template<class _Iterator, class _Container> bool __gnu_cxx::operator==(const __normal_iterator<_Iterator, _Container>&, const __normal_iterator<_Iterator, _Container>&)'
 1216 |     operator==(const __normal_iterator<_Iterator, _Container>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1216:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/predefined_ops.h:270:24: note:   mismatched types 'const __gnu_cxx::__normal_iterator<_Iterator, _Container>' and 'const long long unsigned int'
  270 |         { return *__it == _M_value; }
      |                  ~~~~~~^~~~~~~~~~~