Problem:
Score : 300 points

Problem Statement

There are N integers a_1, a_2, ..., a_N not less than 1.
The values of a_1, a_2, ..., a_N are not known, but it is known that a_1 \times a_2 \times ... \times a_N = P.

Find the maximum possible greatest common divisor of a_1, a_2, ..., a_N.

Constraints

1 \leq N \leq 10^{12}

1 \leq P \leq 10^{12}

Input

Input is given from Standard Input in the following format:

N P

Output

Print the answer.

Sample Input 1

3 24

Sample Output 1

2

The greatest common divisor would be 2 when, for example, a_1=2, a_2=6 and a_3=2.

Sample Input 2

5 1

Sample Output 2

1

As a_i are positive integers, the only possible case is a_1 = a_2 = a_3 = a_4 = a_5 = 1.

Sample Input 3

1 111

Sample Output 3

111

Sample Input 4

4 972439611840

Sample Output 4

206

Solution in C# (Mono 4.6.2.0) (judge verdict: Wrong Answer)

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]C - Product and GCD
            var line = ReadLine();
            var N = line[0];
            var P = line[1];

            var lib = new Library.Factorization();
            var factors = lib.SummarizeFactors(P);
            long ans = 1;

            foreach(var f in factors)
            {
                if (f.Value >= N)
                {
                    ans *= f.Key;
                }
            }

            Console.WriteLine(ans);
        }

        static List<long> ReadLine()
        {
            var line = Console.ReadLine();
            var arr = line.Split(' ');

            return arr.Select(x => long.Parse(x)).ToList();
        }
    }
}

namespace Library
{
    class Factorization
    {
        private List<long> factors;

        public List<long> GetFactors(long n)
        {
            //[summary]ある数を素因数分解する

            //別の数を素因数分解することもあるので、最初にかならず初期化
            factors = new List<long>();

            if (n < 2)
            {
                //2より小さい数を受け取った場合
                factors.Add(n);
            }
            else
            {
                Factoring(n);
            }

            return factors;
        }

        private void Factoring(long n)
        {
            //[summary]平方根以下の素数で総当りで割って行く
            //以下リンクを参考に実装
            //https://qiita.com/gushwell/items/561afde2e00bf3380c98

            //"GetFactors"以外から呼び出されることもあるので、かならず初期化
            factors = new List<long>();

            //平方根を求める
            long sqrt = (long)Math.Sqrt(n);

            //2,3,5で割る(割れなくなるまで割り続ける)
            n = DevideWith(n, 2);
            n = DevideWith(n, 3);
            n = DevideWith(n, 5);

            var primes = new List<int> { 7, 11, 13, 17, 19, 23, 29, 31 };
            long i = 0;

            //平方根以下の素数(候補)で総当りで割る
            while (n > 1)
            {
                foreach (var p in primes)
                {
                    if (p + i > sqrt)
                    {
                        //1が素因数に追加されることを防止
                        if (n > 1)
                        {
                            factors.Add(n);
                        }

                        return;
                    }
                    else
                    {
                        n = DevideWith(n, p + i);
                    }
                }

                i += 30;
            }
        }

        private long DevideWith(long n, long d)
        {
            while (n % d == 0)
            {
                factors.Add(d);
                n /= d;
            }

            return n;
        }

        public List<long> GetDivisors(long n)
        {
            //[summary]ある数の約数をすべて列挙

            //素因数分解した結果(素数,指数...)を受け取る
            var primes = SummarizeFactors(n);

            var divisors = new List<long>();
            divisors.Add(1);

            foreach (var p in primes)
            {
                var tmp = new List<long>();

                for (int i = 0; i <= p.Value; i++)
                {
                    long pow = (long)Math.Pow(p.Key, i);

                    foreach (var d in divisors)
                    {
                        tmp.Add(d * pow);
                    }
                }

                divisors = new List<long>(tmp);
            }

            return divisors;
        }

        public Dictionary<long, long> SummarizeFactors(long n)
        {
            //[summary]素因数分解した結果を、素数,指数...にまとめる
            Factoring(n);

            var primes = new Dictionary<long, long>();

            foreach (var f in factors)
            {
                if (primes.ContainsKey(f))
                {
                    primes[f]++;
                }
                else
                {
                    primes.Add(f, 1);
                }
            }

            return primes;
        }

        public long CountDivisors(long n)
        {
            //[summary]ある数の約数の個数を取得

            //素因数分解した結果を受け取る
            var primes = SummarizeFactors(n);

            long count = 1;

            foreach (var v in primes.Values)
            {
                count *= (v + 1);
            }

            return count;
        }
    }
}