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# (.NET Core 3.1.201) (judge verdict: Time Limit Exceeded)

using System;
using System.Collections.Generic;
using System.Linq;
//公約数をだしてその素数を数えればよい？
namespace D
{
    class Program
    {
        public static int max = 0;
        public static List<long> P;
        static void Main(string[] args)
        {
            string[] In = Console.ReadLine().Split(' ');
            long a = long.Parse(In[0]);
            long b = long.Parse(In[1]);
            long g = GCD(a, b);
            P = PrimeFactors(g).ToList();
            int ans = CountPrime(P);
            Console.WriteLine(ans);
        }
        //ユークリッドの互除法
        public static long GCD(long a, long b)
        {
            if (a < b) return GCD(b, a);
            while (true)
            {
                var r = a % b;
                if (r == 0) return b;
                a = b;
                b = r;
            }
        }
        //公約数
        public static IEnumerable<long> PrimeFactors(long n)
        {
            for(int i = 1; i <= n; i++)
            {
                if (n % i == 0) yield return i;
            }
        }
        //素数を数える
        public static int CountPrime(List<long> M)
        {
            int cnt = 1;
            foreach(var m in M)
            {
                if (IsPrime(m)) cnt++;
            }
            return cnt;
        }
        public static bool IsPrime(long num)
        {
            if (num < 2) return false;
            else if (num == 2) return true;
            else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

            double sqrtNum = Math.Sqrt(num);
            for (int i = 3; i <= sqrtNum; i += 2)
            {
                if (num % i == 0)
                {
                    // 素数ではない
                    return false;
                }
            }

            // 素数である
            return true;
        }
    }
}
//TLE
//namespace D
//{
//    class Program
//    {
//        public static int max = 0;
//        public static List<long> P;
//        static void Main(string[] args)
//        {
//            string[] In = Console.ReadLine().Split(' ');
//            long a = long.Parse(In[0]);
//            long b = long.Parse(In[1]);
//            long g = GCD(a, b);
//            P = PrimeFactors(g).ToList();
//            var D = new Dictionary<long, bool>();
//            foreach (var p in P)
//            {
//                D[p] = false;
//            }
//            DFS(0, D);
//            Console.WriteLine(max);
//        }
//        //ユークリッドの互除法
//        public static long GCD(long a, long b)
//        {
//            if (a < b) return GCD(b, a);
//            while (true)
//            {
//                var r = a % b;
//                if (r == 0) return b;
//                a = b;
//                b = r;
//            }
//        }
//        //公約数
//        public static IEnumerable<long> PrimeFactors(long n)
//        {
//            for (int i = 1; i <= n; i++)
//            {
//                if (n % i == 0) yield return i;
//            }
//        }
//        public static void DFS(int index, Dictionary<long, bool> D)
//        {
//            if (index == D.Count)
//            {
//                if (CountTrue(D.Values) > max && ArePrime(D)) max = CountTrue(D.Values);
//                return;
//            }
//            D[P[index]] = false;
//            DFS(index + 1, D);
//            D[P[index]] = true;
//            DFS(index + 1, D);
//        }
//        public static bool ArePrime(Dictionary<long, bool> D)
//        {
//            var L = new List<long>();
//            foreach (var d in D)
//            {
//                if (d.Value) L.Add(d.Key);
//            }
//            if (L.Count == 0) return false;
//            var C = new int[L.Max() + 1];
//            foreach (var l in L)
//            {
//                if (l == 1) continue;
//                int m = 1;
//                while (m * l <= L.Max())
//                {
//                    C[m * l]++;
//                    if (C[m * l] >= 2) return false;
//                    m++;
//                }
//            }
//            return true;
//        }
//        public static int CountTrue(IEnumerable<bool> I)
//        {
//            int ret = 0;
//            foreach (var i in I)
//            {
//                if (i) ret++;
//            }
//            return ret;
//        }
//    }
//}