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# (Mono 4.6.2.0) (judge verdict: Wrong Answer)

using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var A = sc.ReadLong();
        var B = sc.ReadLong();
        var gcd = Gcd(A, B);
        var pf = PrimeFactors(gcd).Distinct();
        var ans = pf.Count() + 1;
        Console.WriteLine(ans);
    }

    static int INF = int.MaxValue;
    static long LINF = long.MaxValue;
    static Random Rand = new Random();
    static Scanner sc = new Scanner();

    static long Gcd(long a, long b)
    {
        var v = new[] { a, b };
        while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
        return v[0];
    }
    static long Lcm(long a, long b)
    {
        return a / Gcd(a, b) * b;
    }
    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;
    }
    static List<long> PrimeFactors(long n)
    {
        var res = new List<long>();
        var tmp = n;
        for (long x = 2; x * x <= n; x++)
        {
            while (tmp % x == 0)
            {
                tmp /= x;
                res.Add(x);
            }
        }
        if (tmp != 1) res.Add(tmp);
        if (res.Count() == 0) res.Add(n);
        return res;
    }
    static IEnumerable<long> Divisor(long n)
    {
        for (int i = 1; i * i <= n; i++)
        {
            if (n % i == 0) yield return i;
        }
    }
    static Result[] ListAll<T1, T2, Result>(IEnumerable<T1> a, IEnumerable<T2> b, Func<T1, T2, Result> f)
    {
        Result[] res = new Result[a.Count() * b.Count()];
        var i = 0;
        foreach (var v in a)
            foreach (var w in b)
                res[i++] = f(v, w);
        return res;
    }
    static IEnumerable<Result> ListAll<T1, T2, Result>(IEnumerable<T1> a, IEnumerable<T2> b, Func<T1, T2, Result> f, Func<T1, T2, bool> s)
    {
        foreach (var v in a)
        {
            foreach (var w in b)
                if (s(v, w)) yield return f(v, w);
        }
    }
}

class Modulo
{
    public readonly int MOD;
    private readonly List<int> Facs = new List<int>() { 1 };

    public Modulo(int mod = 1000000007) { this.MOD = mod; }
    public int Mul(int a, int b) { return (int)(Math.BigMul(a, b) % MOD); }
    public int Div(int a, int b) { return Mul(a, Pow(b, MOD - 2)); }
    public int Pow(int a, int n)
    {
        switch (n)
        {
            case 0:
                return 1;
            case 1:
                return a;
            default:
                int p1 = Pow(a, n / 2);
                int p2 = Mul(p1, p1);
                return ((n % 2) == 0) ? p2 : Mul(p2, a);
        }
    }
    public int Fac(int n)
    {
        for (int i = this.Facs.Count; i <= n; i++)
        {
            this.Facs.Add(Mul(i, Facs[i - 1]));
        }
        return this.Facs[n];
    }
    public int nPr(int n, int r) => Div(Fac(n), Fac(n - r));
    public int nCr(int n, int r)
    {
        if (n < r) return 0;
        if (n == r) return 1;
        int res = Fac(n);
        res = Div(res, Fac(r));
        res = Div(res, Fac(n - r));
        return res;
    }
}

class Debug
{
    public static void Dump<T>(T[,] array)
    {
        Console.WriteLine();
        var h = array.GetLength(0);
        var w = array.GetLength(1);

        for (int r = 0; r < h; r++)
        {
            for (int c = 0; c < w; c++)
            {
                Console.Write(array[r, c]);
                Console.Write(" ");
            }
            Console.WriteLine();
        }
        Console.WriteLine();
    }
    public static void Dump<T>(T[] array)
    {
        Console.WriteLine();
        Console.WriteLine(string.Join(" ", array));
        Console.WriteLine();
    }
}

class Scanner
{
    string[] S = new string[0];
    int Index = 0;
    char[] Separators = new char[] { ' ' };

    public string Next()
    {
        if (this.Index < this.S.Length) return this.S[this.Index++];
        var line = "";
        while (line == "") line = Console.ReadLine();
        this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
        if (this.S.Length == 0) return this.Next();
        this.Index = 0;
        return this.S[this.Index++];
    }

    public string ReadStr()
    {
        return this.Next();
    }

    public char ReadChar()
    {
        return this.Next()[0];
    }

    public int ReadInt()
    {
        return int.Parse(this.Next());
    }

    public uint ReadUInt()
    {
        return uint.Parse(this.Next());
    }

    public long ReadLong()
    {
        return long.Parse(this.Next());
    }

    public int[] ReadIntArray(int n)
    {
        var array = new int[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadInt();
        }
        return array;
    }

    public long[] ReadLongArray(int n)
    {
        var array = new long[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadLong();
        }
        return array;
    }

    public char[] ReadCharArray(int n)
    {
        var array = new char[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadChar();
        }
        return array;
    }

    public string[] ReadStrArray(int n)
    {
        var array = new string[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadStr();
        }
        return array;
    }
}

class HashMap<K, V> : Dictionary<K, V> where V : new()
{
    private V DefaltValue = new V();
    public HashMap() { }
    public HashMap(V defaultValue)
    {
        this.DefaltValue = new V();
    }
    new public V this[K i]
    {
        get
        {
            V v;
            return TryGetValue(i, out v) ? v : base[i] = this.DefaltValue;
        }
        set { base[i] = value; }
    }
}

class Vector<T> : List<T> where T : new()
{
    public Vector() { }
    public Vector(int count, T defaultValue)
    {
        for (int i = 0; i < count; i++)
        {
            this.Add(defaultValue);
        }
    }
}

class PriorityQueue<T> where T : IComparable<T>
{
    public readonly T[] Array;
    public readonly bool Greater;
    public int Count { get; private set; } = 0;

    public PriorityQueue(int capacity, bool greater = true)
    {
        this.Array = new T[capacity];
        this.Greater = greater;
    }

    public void Enqueue(T item)
    {
        this.Array[this.Count] = item;
        this.Count += 1;
        this.UpHeap();
    }

    public T Dequeue()
    {
        this.Swap(0, this.Count - 1);
        this.Count -= 1;
        this.DownHeap();

        return this.Array[this.Count];
    }

    public T Peek()
    {
        return this.Array[0];
    }

    private void UpHeap()
    {
        var n = this.Count - 1;
        while (n != 0)
        {
            var parent = (n - 1) / 2;

            if (this.Array[n].CompareTo(this.Array[parent]) > 0)
            {
                this.Swap(n, parent);
                n = parent;
            }
            else
            {
                break;
            }
        }
    }

    private void DownHeap()
    {
        var parent = 0;
        while (true)
        {
            var child = 2 * parent + 1;
            if (child > this.Count - 1) break;

            if (child < this.Count - 1 && this.Compare(this.Array[child], this.Array[child + 1]) < 0)
            {
                child += 1;
            }

            if (this.Compare(this.Array[parent], this.Array[child]) < 0)
            {
                this.Swap(parent, child);
                parent = child;
            }
            else
            {
                break;
            }
        }
    }

    private int Compare(T a, T b)
    {
        var c = a.CompareTo(b);
        if (!this.Greater)
        {
            c = -c;
        }
        return c;
    }

    private void Swap(int a, int b)
    {
        var tmp = this.Array[a];
        this.Array[a] = this.Array[b];
        this.Array[b] = tmp;
    }
}