Problem:
Score : 400 points

Problem Statement

Given are positive integers A and B.

Let us choose some number of positive common divisors of A and B.

Here, any two of the chosen divisors must be coprime.

At most, how many divisors can we choose?

Definition of common divisor

An integer d is said to be a common divisor of integers x and y when d divides both x and y.

Definition of being coprime

Integers x and y are said to be coprime when x and y have no positive common divisors other than 1.

Definition of dividing

An integer x is said to divide another integer y when there exists an integer \alpha such that y = \alpha x.

Constraints

All values in input are integers.

1 \leq A, B \leq 10^{12}

Input

Input is given from Standard Input in the following format:

A B

Output

Print the maximum number of divisors that can be chosen to satisfy the condition.

Sample Input 1

12 18

Sample Output 1

3

12 and 18 have the following positive common divisors: 1, 2, 3, and 6.

1 and 2 are coprime, 2 and 3 are coprime, and 3 and 1 are coprime, so we can choose 1, 2, and 3, which achieve the maximum result.

Sample Input 2

420 660

Sample Output 2

4

Sample Input 3

1 2019

Sample Output 3

1

1 and 2019 have no positive common divisors other than 1.

Solution in C++14 (GCC 5.4.1) (judge verdict: Runtime Error)

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define Khela ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define llu long long unsigned int
#define pf printf
#define sf scanf
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define pii pair<int ,int>
#define PII pair<ll, ll>

int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
 
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
int Set(int N,int pos){return N=N | (1<<pos);}
int reset(int N,int pos){return N= N & ~(1<<pos);}
bool check(int N,int pos){return (bool)(N & (1<<pos));}
const int Max=1e9+100;
const int sz=1e4+100;
bool mark[sz];
vector<ll> prime;
int siz;
void seive()
{
    ll i,j,k;
    ll sq=sqrt(sz);
    for(i=3;i<sz;i+=2)
    {
       mark[i]=true;
    }
    prime.pb(2);
    for(i=3;i<=sq;i+=2)
    {
        if(mark[i])
        {
            for(j=i*i;j<sz;j+=2*i) mark[j]=false;
        }
    }
    mark[1]=true;
    for(i=3;i<sz;i+=2) if(mark[i]) prime.pb(i);
    siz=prime.size();
}

ll fact(ll x)
{
      ll ct=0;
      int i,j,k;
      if(x>0) ++ct;
      ll sq=sqrt(x);
      for(i=0;i<siz && prime[i]<=sq;i++)
      {
          if(mark[x]) break;
          if(x%prime[i]==0)
          {
              ++ct;
              while(x%prime[i]==0) x/=prime[i];
              sq=sqrt(x);
          }
          
      }

      if(x>1) ++ct;
      return ct;
}
int main()
{
    Khela
    ll a,b,c,i,j,k,q,p,x,y,ct,ct1,m,l,r,x1,y1,mn,h,sum1,in,z,mid,n,mx;
    char ch;
    double d;
    string str1,str2,str;
    bool bl,bl1;
    int t,cs=1;
    seive();
    while(cin>>p>>q)
    {
        n=__gcd(p,q);
        ll ans=fact(n);
        cout<<ans<<endl;
    }

}