Language: C++

#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#define Abs(x)((x) < 0 ? (x) * -1 : (x))
 
#define rep(x, y) for ((x) = 0; (x) < (y); (x)++)
#define repin(x, y) for ((x) = 0; (x) <= (y); (x)++)
#define nep(x, y) for ((x) = (y) - 1; 0 <= (x); (x)--)
#define nepi(x, y, z) for ((x) = (y) - 1; (z) <= (x); (x)--)
#define repi(x, y, z) for ((x) = (z); (x) < (y); (x)++)
#define repiin(x, y, z) for ((x) = (z); (x) <= (y); (x)++)
#define reps(x, y, z) for ((x) = 0; (x) < (y); (x) += (z))
#define repis(x, y, z, s) for ((x) = (z); (x) < (y); (x) += (s))
#define repiins(x, y, z, s) for ((x) = (z); (x) <= (y); (x) += (s))
#define repit(x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define repit2(x) for (__typeof((x).begin()) it2 = (x).begin(); it2 != (x).end(); it2++)
#define nepit(x) for (__typeof((x).rbegin()) it = (x).rbegin(); it != (x).rend(); it++)
 
#define All(x) (x).begin(),(x).end()
 
#define Mem0(x) memset(x, 0, sizeof(x))
#define Mem1(x) memset(x, -1, sizeof(x))
 
// can be applied to string type
#define Unique(v) v.resize(unique(All(v)) - v.begin())
 
#define peq(p0, p1)(p0.first == p1.first && p0.second == p1.second)
 
#define End '\n'
#define Out(x) cout<<(x)<<End
#define YES cout<<"YES"<<End
#define NO cout<<"NO"<<End
#define Yes cout<<"Yes"<<End
#define No cout<<"No"<<End
template<typename T>
void Outln(const string &sep, const T &val) { cout << val << End; }
template<typename T, typename... Args>
void Outln(const string &sep, const T &val, Args... args) {
    cout << val << sep;
	Outln(sep, std::forward<Args>(args)...);
}
template<typename T>
void OutN(T x) {
	size_t i, len = x.size() - 1;
 
	for (i = 0; i < len; i++) cout << x[i] << " ";
	cout << x[len] << '\n';
}
#define OutaN(x)                                                     \
    do {                                                             \
        size_t i, len = sizeof(x) / sizeof(__typeof(x[0])) - 1;      \
        for (i = 0; i < len; i++) cout << x[i] << " ";               \
        cout << x[len] << '\n';                                      \
    } while (0);
 
template<typename T>
void Outit(T x) {
	auto end = x.end();
 
	end--;
	
	for (auto it = x.begin(); it != end; it++) cout << *it << " ";
	cout << *end << '\n';
}
template<typename T>
void Debug(const T &val) { cerr << val << End; }
template<typename T, typename... Args>
void Debug(const T &val, Args... args) {
    cerr << val << ' ';
	Debug(std::forward<Args>(args)...);
}
 
template<typename T> inline bool Max(T &x, const T &y) { return x < y ? x = y, 1 : 0; }
template<typename T> inline bool Min(T &x, const T &y) { return x > y ? x = y, 1 : 0; }
template<typename T> using V = vector<T>;
template<typename T> using VV = V<V<T> >;
 
// can be applied to string type
#define Sort(v) sort(All(v))
#define SortR(v) sort(All(v), std::greater<__typeof(v[0])>())
// array sorters
#define Sart(a) sort(a, a + sizeof(a) / sizeof(__typeof(a[0])));
#define SartR(a) sort(a, a + sizeof(a) / sizeof(__typeof(a[0])), std::greater<__typeof(a[0])>())
 
#define pb push_back
#define mp make_pair
#define a first
#define b second
#define lb std::lower_bound
#define ub std::upper_bound
 
#define lbi(v, x) lb(All(v), (x))-v.begin()
#define ubi(v, x) ub(All(v), (x))-v.begin()
 
inline bool isSame(const string &a, const string &b) { return a.compare(b) == 0; }
inline bool isLess(const string &a, const string &b) { return a.compare(b) < 0; }
inline bool isGreater(const string &a, const string &b) { return a.compare(b) > 0; }
inline string Str(const char &ch, const int &n) { return string(n, ch); }
inline string Str(const int &n, const char &ch) { return string(n, ch); }
vector<string> getStrLine() {
	vector<string> v;
	string str;
 
	getline(cin, str);
 
	istringstream iss(str);
 
	for (string word; iss >> word;) v.push_back(word);
 
	return v;
}
 
static const ll MOD = 1e9 + 7;
static const double PI = 3.141592653589793;
 
#define LOCAL 0
 
int main()
{
#if LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#endif
 
    cin.tie(0);
    ios::sync_with_stdio(false);
	//std::cout.precision(18);
 
    ll a, b;

	cin >> a >> b;

	if (a == 1 || b == 1) {
		Out(1);
	} else if (a == 2 || b == 2) {
		if (a == 2 && b % 2 == 0) Out(2);
		else if (a == 2 && b % 2 == 1) Out(1);
		else if (b == 2 && a % 2 == 0) Out(2);
		else Out(1);
	} else {
		set<ll> table;
		set<ll> b;
		ll n = __gcd(a, b);
		bool found;

		if (a % 2 == 0 && b % 2 == 0) table.insert(2);
		
	    ll i, len = sqrt(n);
		
		repiins(i, len, 3, 2) {
			if (n % i == 0) {
			    if (n / i == i) {
					found = false;
 
					repit(table) {
						if (table.find(i) != table.end()) {
							found = true;
 
							break;
						}
					}
 
					if (!found)table.insert(i);
				} else {
					found = false;
 
					repit(table) {
						if (table.find(i) != table.end()) {
							found = true;
 
							break;
						}
					}
 
					if (!found)table.insert(i);

					b.insert(n / i);
				}
			}
		}

		repit(b) {
			if (table.find(*it) == table.end()) table.insert(*it);
		}

		found = false;
		repit(table) {
			if (table.find(n) != table.end()) {
				found = true;

				break;
			}
		}
		if (!found) table.insert(n);

		if (b < a) swap(a, b);
		found = false;
		repit(table) {
			if (table.find(a) != table.end()) {
				found = true;

				break;
			}
		}
		if (!found) table.insert(a);

	    Out(table.size() + 1);
	}
	
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:148:29: error: no matching function for call to '__gcd(ll&, std::set<long long int>&)'
  148 |                 ll n = __gcd(a, b);
      |                        ~~~~~^~~~~~
In file included from /usr/include/c++/14/algorithm:61,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algo.h:1137:5: note: candidate: 'template<class _EuclideanRingElement> _EuclideanRingElement std::__gcd(_EuclideanRingElement, _EuclideanRingElement)'
 1137 |     __gcd(_EuclideanRingElement __m, _EuclideanRingElement __n)
      |     ^~~~~
/usr/include/c++/14/bits/stl_algo.h:1137:5: note:   template argument deduction/substitution failed:
a.cc:148:29: note:   deduced conflicting types for parameter '_EuclideanRingElement' ('long long int' and 'std::set<long long int>')
  148 |                 ll n = __gcd(a, b);
      |                        ~~~~~^~~~~~
a.cc:151:37: error: no match for 'operator%' (operand types are 'std::set<long long int>' and 'int')
  151 |                 if (a % 2 == 0 && b % 2 == 0) table.insert(2);
      |                                     ^ ~
      |                                       |
      |                                       int
In file included from /usr/include/c++/14/valarray:605,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:166:
/usr/include/c++/14/bits/valarray_after.h:409:5: note: candidate: 'template<class _Dom1, class _Dom2> std::_Expr<std::__detail::_BinClos<std::__modulus, std::_Expr, std::_Expr, _Dom1, _Dom2>, typename std::__fun<std::__modulus, typename _Dom1::value_type>::result_type> std::operator%(const _Expr<_Dom1, typename _Dom1::value_type>&, const _Expr<_Dom2, typename _Dom2::value_type>&)'
  409 |     _DEFINE_EXPR_BINARY_OPERATOR(%, struct std::__modulus)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/valarray_after.h:409:5: note:   template argument deduction/substitution failed:
a.cc:151:39: note:   'std::set<long long int>' is not derived from 'const std::_Expr<_Dom1, typename _Dom1::value_type>'
  151 |                 if (a % 2 == 0 && b % 2 == 0) table.insert(2);
      |                                       ^
/usr/include/c++/14/bits/valarray_after.h:409:5: note: candidate: 'template<class _Dom> std::_Expr<std::__detail::_BinClos<std::__modulus, std::_Expr, std::_Constant, _Dom, typename _Dom::value_type>, typename std::__fun<std::__modulus, typename _Dom1::value_type>::result_type> std::operator%(const _Expr<_Dom1, typename _Dom1::value_type>&, const typename _Dom::value_type&)'
  409 |     _DEFINE_EXPR_BINARY_OPERATOR(%, struct std::__modulus)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/valarray_after.h:409:5: note:   template argument deduction/substitution failed:
a.cc:151:39: note:   'std::set<long long int>' is not derived from 'const std::_Expr<_Dom1, typename _Dom1::value_type>'
  151 |                 if (a % 2 == 0 && b % 2 == 0) table.insert(2);
      |                                       ^
/usr/include/c++/14/bits/valarray_after.h:409:5: note: candidate: 'template<class _Dom> std::_Expr<std::__detail::_BinClos<std::__modulus, std::_Constant, std::_Expr, typename _Dom::value_type, _Dom>, typename std::__fun<std::__modulus, typename _Dom1::value_type>::result_type> std::operator%(const typename _Dom::value_type&, const _Expr<_Dom1, typename _Dom1::value_type>&)'
  409 |     _DEFINE_EXPR_BINARY_OPERATOR(%, struct std::__modulus)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/valarray_after.h:409:5: note:   template argument deduction/substitution failed:
a.cc:151:39: note:   mismatched types 'const std::_Expr<_Dom1, typename _Dom1::value_type>' and 'int'
  151 |                 if (a % 2 == 0 && b % 2 == 0) table.insert(2);
      |                                       ^
/usr/include/c++/14/bits/valarray_after.h:409:5: note: candidate: 'template<class _Dom> std::_Expr<std::__detail::_BinClos<std::__modulus, std::_Expr, std::_ValArray, _Dom, typename _Dom::value_type>, typename std::__fun<std::__modulus, typename _Dom1::value_type>::result_type> std::operator%(const _Expr<_Dom1, typename _Dom1::value_type>&, const valarray<typename _Dom::value_type>&)'
  409 |     _DEFINE_EXPR_BINARY_OPERATOR(%, struct std::__modulus)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/valarray_after.h:409:5: note:   template argument deduction/substitution failed:
a.cc:151:39: note:   'std::set<long long int>' is not derived from 'const std::_Expr<_Dom1, typename _Dom1::value_type>'
  151 |                 if (a % 2 == 0 && b % 2 == 0) table.insert(2);
      |                                       ^
/usr/include/c++/14/bits/valarray_after.h:409:5: note: candidate: 'template<class _Dom> std::_Expr<std::__detail::_BinClos<std::__modulus, std::_ValArray, std::_Expr, typename _Dom::value_type, _Dom>, typename std::__fun<std::__modulus, typename _Dom1::value_type>::result_type> std::operator%(const valarray<typename _Dom::value_type>&, const _Expr<_Dom1, typename _Dom1::value_type>&)'
  409 |     _DEFINE_EXPR_BINARY_OPERATOR(%, struct std::__modulus)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/valarray_after.h:409:5: note:   template argument deduction/substitution failed:
a.cc:151:39: note:   mismatched types 'const std::_Expr<_Dom1, typename _Dom1::value_type>' and 'int'
  151 |                 if (a % 2 == 0 && b % 2 == 0) table.insert(2);
      |                                       ^
/usr/include/c++/14/valarray:1200:1: note: candidate: 'template<class _Tp> std::_Expr<std::__detail::_BinClos<std::__modulus, std::_ValArray, std::_ValArray, _Tp, _Tp>, typename std::__fun<std::__modulus, _Tp>::result_type> std::operator%(const valarray<_Tp>&, const valarray<_Tp>&)'
 1200 | _DEFINE_BINARY_OPERATOR(%, __modulus)
      | ^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/valarray:1200:1: note:   template argument deduction/substitution failed:
a.cc:151:39: note:   'std::set<long long int>' is not derived from 'const std::valarray<_Tp>'
  151 |                 if (a % 2 == 0 && b % 2 == 0) table.insert(2);
      |                                       ^
/usr/include/c++/14/valarray:1200:1: note: candidate: 'template<class _Tp> std::_Expr<std::__detail::_BinClos<std::__modulus, std::_ValArray, std::_Constant, _Tp, _Tp>, typename std::__fun<std::__modulus, _Tp>::result_type> std::operator%(const valarray<_Tp>&, const typename valarray<_Tp>::value_type&)'
 1200 | _DEFINE_BINARY_OPERATOR(%, __modulus)
      | ^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/valarray:1200:1: note:   template argument deduction/substitution failed:
a.cc:151:39: note:   'std::set<long long int>' is not derived from 'const std::valarray<_Tp>'
  151 |                 if (a % 2 == 0 && b % 2 == 0) table.insert(2);
      |                                       ^
/usr/include/c++/14/valarray:1200:1: note: candidate: 'template<class _Tp> std::_Expr<std::__detail::_BinClos<std::__modulus, std::_Constant, std::_ValArray, _Tp, _Tp>, typename std::__fun<std::__modulus, _Tp>::result_type> std::operator%(const typename valarray<_Tp>::value_type&, const valarray<_Tp>&)'
 1200 | _DEFINE_BINARY_OPERATOR(%, __modulus)
      | ^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/valarray:1200:1: note:   template argument deduction/substitution failed:
a.cc:151:39: note:   mismatched types 'const std::valarray<_Tp>' and 'int'
  151 |                 if (a % 2 == 0 && b % 2 == 0) table.insert(2);
      |                                       ^
a.cc:201:23: error: no match for 'operator<' (operand types are 'std::set<long long int>' and 'll' {aka 'long long int'})
  201 |                 if (b < a) swap(a, b);
      |                       ^
In file included from /usr/include/c++/14/regex:68,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:181:
/usr/include/c++/14/bits/regex.h:1143:5: note: candidate: 'template<class _BiIter> bool std::__cxx11::operator<(const sub_match<_BiIter>&, const sub_match<_BiIter>&)'
 1143 |     operator<(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs)
      |     ^~~~~~~~
/usr/include/c++/14/bits/regex.h:1143:5: note:   template argument deduction/substitution failed:
a.cc:91:11: note:   'std::set<long long int>' is not derived from 'const std::__cxx11::sub_match<_BiIter>'
   91 | #define a first
      |           ^~~~~
a.cc:201:25: note: in expansion of macro 'a'
  201 |                 if (b < a) swap(a, b);
      |                         ^
/usr/include/c++/14/bits/regex.h:1224:5: note: candidate: 'template<class _Bi_iter, class _Ch_traits, class _Ch_alloc> bool std::__cxx11::operator<(__sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>&, const sub_match<_BiIter>&)'
 1224 |     operator<(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/regex.h:1224:5: note:   template argument deduction/substitution failed:
a.cc:91:11: note:   'std::set<long long int>' is not derived from 'std::__cxx11::__sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>'
   91 | #define a first
      |           ^~~~~
a.cc:201:25: note: in expansion of macro 'a'
  201 |                 if (b < a) swap(a, b);
      |                         ^
/usr/include/c++/14/bits/regex.h:1317:5: note: candidate: 'template<class _Bi_iter, class _Ch_traits, class _Ch_alloc> bool std::__cxx11::operator<(const sub_match<_BiIter>&, __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>&)'
 1317 |     operator<(const sub_match<_Bi_iter>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/regex.h:1317:5: note:   template argument deduction/substitution failed:
a.cc:91:11: note:   'std::set<long long int>' is not derived from 'const std::__cxx11::sub_match<_BiIter>'
   91 | #define a first
      |           ^~~~~
a.cc:201:25: note: in expansion of macro 'a'
  201 |                 if (b < a) swap(a, b);
      |                         ^
/usr/include/c++/14/bits/regex.h:1391:5: note: candidate: 'template<class _Bi_iter> bool std::__cxx11::operator<(const typename std::iterator_traits<_Iter>::value_type*, const sub_match<_BiIter>&)'
 1391 |     operator<(typename