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: Accepted)

using Microsoft.VisualBasic.CompilerServices;
using System;
using System.Collections.Generic;
using System.Linq;
//公約数をだしてその素数を数えればよい？
namespace D
{
    class Program
    {
        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);
            var ans = CountPrime(g);
            Console.WriteLine(ans.Count+1);
        }
        //ユークリッドの互除法
        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 Dictionary<long,int> CountPrime(long n)
        {
            var res = new Dictionary<long, int>();
            for(long i=2; i * i <= n; i++)
            {
                if (n % i != 0) continue;
                res[i] = 0;
                while (n % i == 0)//ここで計算量減らす
                {
                    n /= i;
                    res[i]++;
                }
            }
            if (n != 1) res[n] = 1;
            return res;
        }
      
    }
    public struct Pair
    {
        public long x;
        public int y;
    }
}
//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;
//        }
//    }
//}