Language: C++

#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <climits>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
//#include <tuple>

#define INF INT_MAX>>1 
#define SIZE 100010
#define MOD 1000000007
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define rep2(i, from, to) for(int i=(from); i<(int)(to); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define LLPair pair<ll, ll>
#define vint vector<int>
#define vll vector<ll>
typedef long long ll;

using namespace std;

struct Point { int x, y; };
struct Edge { int from, to, cost; };
struct gNode { int from, to, cost; };
struct tNode { int value; int parent; vector<int> child; };

int dx[] ={-1, 0, 0, 1};
int dy[] ={0, -1, 1, 0};

int gcd(int a, int b){ return a % b == 0 ? b : gcd(b, a%b); }
int lcm(int a, int b){ return a * b/ gcd(a, b); }
int extgcd(int a, int b, int& x, int& y){
	int d = a;
	if(b != 0){
		d = extgcd(b, a%b, y, x);
		y -= (a/b) * x;
	} else{
		x = 1; y = 0;
	}
	return d;
}
ll mod_pow(ll x, ll n){
	if(n == 0) return 1;
	ll res = mod_pow(x*x % MOD, n/2);
	if(n & 1) res = res * x % MOD;
	return res;
}

#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <climits>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
//#include <tuple>

#define INF INT_MAX>>1 
#define SIZE 100010
#define MOD 1000000007
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define rep2(i, from, to) for(int i=(from); i<(int)(to); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define LLPair pair<ll, ll>
#define vint vector<int>
#define vll vector<ll>
typedef long long ll;

using namespace std;

struct Point { int x, y; };
struct Edge { int from, to, cost; };
struct gNode { int from, to, cost; };
struct tNode { int value; int parent; vector<int> child; };

int dx[] ={-1, 0, 0, 1};
int dy[] ={0, -1, 1, 0};

int gcd(int a, int b){ return a % b == 0 ? b : gcd(b, a%b); }
int lcm(int a, int b){ return a * b/ gcd(a, b); }
int extgcd(int a, int b, int& x, int& y){
	int d = a;
	if(b != 0){
		d = extgcd(b, a%b, y, x);
		y -= (a/b) * x;
	} else{
		x = 1; y = 0;
	}
	return d;
}
ll mod_pow(ll x, ll n){
	if(n == 0) return 1;
	ll res = mod_pow(x*x % MOD, n/2);
	if(n & 1) res = res * x % MOD;
	return res;
}

ll sq = sqrt(1'000'000'000'000);
bool isprime[1000100];

int sieve(ll n){
	int p=0;
	fill(isprime, isprime+sq+50, true);
	isprime[0] = isprime[1] = false;
	for(int i=2; i<=n; i++){
		if(isprime[i]){
			for(int j=2*i; j<=n; j+=i){
				isprime[j] = false;
			}
		}
	}
	isprime[1] = true;
}

int main(void){
	ll a, b; cin >> a >> b;
	sieve(sq);

	int ans = 0;
	vint cans;
	rep2(i, 1, min(sq, max(a, b))){
		if(isprime[i]){
			if(a%i == 0 && b%i == 0){
				ans++;
			}
		}
	}
	cout << ans << endl;
	return 0;
}


////int sq = sqrt(1'000'000'000'000)+1;
////bool isprime[1000100];
////int prime[1000100];
////
////int sieve(int n){
////	int p=0;
////	fill(isprime, isprime+sq+50, true);
////	isprime[0] = isprime[1] = false;
////	ll sum = 1;
////	for(int i=2; i<=n; i++){
////		if(isprime[i]){
////			prime[p++] = i;
////			sum *= i;
////			cout << i << ",";
////			if(sum > 1'000'000'000'000) return 1;
////			for(int j=2*i; j<=n; j+=i){
////				isprime[j] = false;
////			}
////		}
////
////	}
////	isprime[1] = true;
////}
//
//int prime[14] ={1, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41};
//
//int main(void){
//	int a, b; cin >> a >> b;
//	int ans = 0;
//	for(int i=0; i<14; i++){
//		if(min(a, b) < prime[i]) break;
//		if(a%prime[i] == 0 && b%prime[i] == 0) ans++;
//	}
//	cout << ans << endl;
//	return 0;
//}
//
////int main(void){
////	int a, b; cin >> a >> b;
////	sieve(sq);
////
////	a=840;
////	b=420;
////	int ans = 0;
////	rep2(i, 1, sq+1){
////		if(isprime[i]){
////			if(a>=i && b>=i && a%i == 0 && b%i == 0){
////				ans++;
////			}
////		}
////	}
////	cout << a << " " << b << " :  ";
////	cout << ans << endl;
////
////	//for(int t1=1; t1<100; t1++){
////	//	for(int t2=2; t2<100; t2++){
////	//		a=t1;
////	//		b=t2;
////	//		int ans = 0;
////	//		rep2(i, 1, sq+1){
////	//			if(isprime[i]){
////	//				if(a>=i && b>=i && a%i == 0 && b%i == 0){
////	//					ans++;
////	//				}
////	//			}
////	//		}
////	//		cout << a << " " << b << " :  ";
////	//		cout << ans << endl;
////	//	}
////	//}
////	return 0;
////}

Compiler output:
a.cc:88:8: error: redefinition of 'struct Point'
   88 | struct Point { int x, y; };
      |        ^~~~~
a.cc:31:8: note: previous definition of 'struct Point'
   31 | struct Point { int x, y; };
      |        ^~~~~
a.cc:89:8: error: redefinition of 'struct Edge'
   89 | struct Edge { int from, to, cost; };
      |        ^~~~
a.cc:32:8: note: previous definition of 'struct Edge'
   32 | struct Edge { int from, to, cost; };
      |        ^~~~
a.cc:90:8: error: redefinition of 'struct gNode'
   90 | struct gNode { int from, to, cost; };
      |        ^~~~~
a.cc:33:8: note: previous definition of 'struct gNode'
   33 | struct gNode { int from, to, cost; };
      |        ^~~~~
a.cc:91:8: error: redefinition of 'struct tNode'
   91 | struct tNode { int value; int parent; vector<int> child; };
      |        ^~~~~
a.cc:34:8: note: previous definition of 'struct tNode'
   34 | struct tNode { int value; int parent; vector<int> child; };
      |        ^~~~~
a.cc:93:5: error: redefinition of 'int dx []'
   93 | int dx[] ={-1, 0, 0, 1};
      |     ^~
a.cc:36:5: note: 'int dx [4]' previously defined here
   36 | int dx[] ={-1, 0, 0, 1};
      |     ^~
a.cc:94:5: error: redefinition of 'int dy []'
   94 | int dy[] ={0, -1, 1, 0};
      |     ^~
a.cc:37:5: note: 'int dy [4]' previously defined here
   37 | int dy[] ={0, -1, 1, 0};
      |     ^~
a.cc:96:5: error: redefinition of 'int gcd(int, int)'
   96 | int gcd(int a, int b){ return a % b == 0 ? b : gcd(b, a%b); }
      |     ^~~
a.cc:39:5: note: 'int gcd(int, int)' previously defined here
   39 | int gcd(int a, int b){ return a % b == 0 ? b : gcd(b, a%b); }
      |     ^~~
a.cc:97:5: error: redefinition of 'int lcm(int, int)'
   97 | int lcm(int a, int b){ return a * b/ gcd(a, b); }
      |     ^~~
a.cc:40:5: note: 'int lcm(int, int)' previously defined here
   40 | int lcm(int a, int b){ return a * b/ gcd(a, b); }
      |     ^~~
a.cc:98:5: error: redefinition of 'int extgcd(int, int, int&, int&)'
   98 | int extgcd(int a, int b, int& x, int& y){
      |     ^~~~~~
a.cc:41:5: note: 'int extgcd(int, int, int&, int&)' previously defined here
   41 | int extgcd(int a, int b, int& x, int& y){
      |     ^~~~~~
a.cc:108:4: error: redefinition of 'll mod_pow(ll, ll)'
  108 | ll mod_pow(ll x, ll n){
      |    ^~~~~~~
a.cc:51:4: note: 'll mod_pow(ll, ll)' previously defined here
   51 | ll mod_pow(ll x, ll n){
      |    ^~~~~~~
a.cc: In function 'int sieve(ll)':
a.cc:130:1: warning: no return statement in function returning non-void [-Wreturn-type]
  130 | }
      | ^