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



Sample input:
3 24


Sample output:
2

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/caddi2018/tasks/caddi2018_a

import sys
input = sys.stdin.readline

N, P = [int(x) for x in input().split()]

# 素因数分解
# 考え方：1~√nまで実際に割れるか試せば良いが、割れた場合は割れる限りその数で割り続ける
# 計算量：O(√n)
def prime_factorize(n):
    i = 2
    primes = []
    while i * i <= n:
        if n % i != 0:
            i += 1
            continue
        exp = 0
        while n % i == 0:
            exp += 1
            n = n // i
        primes.append([i, exp])
        i += 1
    # 最後に残った数は1か素数にしかならない
    if n != 1:
        primes.append([n, 1])
    return primes

primes = prime_factorize(P)

max_gcd_primes = [[prime[0],prime[1]//N] for prime in primes]
max_gcd = 1
for prime in max_gcd_primes:
    max_gcd *= prime[0] ** prime[1]
print(max_gcd)

Submission status: Accepted

Solution code:
def main():
    n, p = list(map(int, input().split()))
    def factorization(num):
        result = []
        count = 0
        temp = num
        for i in range(2, int(num ** 0.5) + 1):
            if temp % i == 0:
                count = 0
                while temp % i == 0:
                    count += 1
                    temp /= i
                result.append([i, count])
        if temp != 1:
            result.append([int(temp), 1])
        if result == []:
            result.append([num, 1])
        return result
    ans = 1
    for (fac, cnt) in factorization(p):
        ans *= pow(fac, cnt // n)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import sys
from typing import Any, Callable, Deque, Dict, List, Mapping, Optional, Sequence, Set, Tuple, TypeVar, Union
# import time
# import math
# import numpy as np
# import scipy.sparse.csgraph as cs            # csgraph_from_dense(ndarray, null_value=inf), bellman_ford(G, return_predecessors=True), dijkstra, floyd_warshall
# import random                                # random, uniform, randint, randrange, shuffle, sample
# import string                                # ascii_lowercase, ascii_uppercase, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from datetime import date, datetime          # date.today(), date(year,month,day) => date obj; datetime.now(), datetime(year,month,day,hour,second,microsecond) => datetime obj; subtraction => timedelta obj
# from datetime.datetime import strptime       # strptime('2019/01/01 10:05:20', '%Y/%m/%d/ %H:%M:%S') returns datetime obj
# from datetime import timedelta               # td.days, td.seconds, td.microseconds, td.total_seconds(). abs function is also available.
# from copy import copy, deepcopy              # use deepcopy to copy multi-dimentional matrix without reference
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from fractions import Fraction               # Fraction(a, b) => a / b ∈ Q. note: Fraction(0.1) do not returns Fraciton(1, 10). Fraction('0.1') returns Fraction(1, 10)



def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79e+308
    # inf = 2 ** 63 - 1             # (for fast JIT compile in PyPy) 9.22e+18
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def isp():   return input().split()
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    import math
    class Eratos:
        def __init__(self, num):
            '''
            O(nlglgn) で num までの素数判定テーブルを作る
            >>> e = Eratos(10)
            >>> e.table
            [False, False, True, True, False, True, False, True, False, False, False]
            '''
            assert(num >= 1)
            self.table_max = num
            # self.table[i] は i が素数かどうかを示す (bool)
            self.table = [False if i == 0 or i == 1 else True for i in range(num+1)]
            for i in range(2, int(math.sqrt(num)) + 1):
                if self.table[i]:
                    for j in range(i ** 2, num + 1, i):    # i**2 からスタートすることで定数倍高速化できる
                        self.table[j] = False
        
        def is_prime(self, num):
            '''
            O(1) で素数判定を行う
            >>> e = Eratos(100)
            >>> [i for i in range(1, 101) if e.is_prime(i)]
            [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]
            '''
            assert(num >= 1)
            if num > self.table_max:
                raise ValueError('Eratos.is_prime(): exceed table_max({}). got {}'.format(self.table_max, num))
            return self.table[num]
        
        def prime_factorize(self, num):
            '''
            O(√n) で素因数分解を行う
            >>> e = Eratos(10000)
            >>> e.prime_factorize(6552)
            {2: 3, 3: 2, 7: 1, 13: 1}
            '''
            assert(num >= 1)
            if int(math.sqrt(num)) > self.table_max:
                raise ValueError('Eratos.prime_factorize(): exceed prime table size. got {}'.format(num))
            # 素因数分解の結果を記録する辞書        
            factorized_dict = dict()
            candidate_prime_numbers = [i for i in range(2, int(math.sqrt(num)) + 1) if self.is_prime(i)]
            # n について、√n 以下の素数で割り続けると最後には 1 or 素数となる
            # 背理法を考えれば自明 (残された数が √n より上の素数の積であると仮定。これは自明に n を超えるため矛盾)
            for p in candidate_prime_numbers:
                if num == 1:    # これ以上調査は無意味
                    break
                if num % p == 0:
                    cnt = 0
                    while num % p == 0:
                        num //= p
                        cnt += 1
                    factorized_dict[p] = cnt
            if num != 1:
                factorized_dict[num] = 1
            return factorized_dict
        
    
    n, p = mi()
    e = Eratos(10 ** 6 + 1)

    if p == 1:
        print(1)
    else:
        d = e.prime_factorize(p)
        # print(d)
        gcd = 1
        for k, v in d.items():
            if v >= n:
                gcd *= k ** (v // n)
        print(gcd)



if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
    N, P = (int(i) for i in input().split())

    def prime_factorize(n):
        res = []
        for i in range(2, n+1):
            if i*i > n:
                break
            if n % i != 0:
                continue
            ex = 0
            while n % i == 0:
                ex += 1
                n //= i
            res.append((i, ex))
        if n != 1:
            res.append((n, 1))
        return res

    pf = prime_factorize(P)
    ans = 1
    for p, e in pf:
        ans *= p**(e//N)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    N, P = (int(i) for i in input().split())

    def enum_divisors(n):
        # 約数列挙
        divs = []
        for i in range(1, n+1):
            if i*i > n:
                break
            if n % i == 0:
                divs.append(i)
                if n//i != i:
                    # i が平方数でない
                    divs.append(n//i)
        return divs

    divs = enum_divisors(P)
    divs.sort()
    ans = 1
    for d in divs[-1:0:-1]:
        v = 1
        for _ in range(N):
            v *= d
            if v > P:
                break
        else:
            if P % v == 0:
                ans = d
                break
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n, p = map(int, input().split())

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

p_nums = factorization(p)

ans = 1

for i, j in p_nums:
    if j >= n:
        ans *= i ** (j // n)
print(ans)

Submission status: Accepted

Solution code:
def prime_factorize(n):
    cnt = {}
    f = 2
    while f * f <= n:
        if n%f != 0:
            f += 1
            continue
        cnt.setdefault(f, 0)
        cnt[f] += 1
        n //= f
    if n > 1:
        cnt.setdefault(n, 0)
        cnt[n] += 1
    return cnt
n, p = map(int, input().split())
cnt = prime_factorize(p)
ans = 1
for k, v in cnt.items():
    ans *= k ** (v//n)
print(ans)

Submission status: Accepted

Solution code:
import math
def myFactorization(n):
    '''nを素因数分解する

    戻り値: factList = [[prime1, exp1], [prime2, exp2],...] 
           n=(prime1)**exp1 * (prime2)**exp2 * ...
    '''

    factList=[]
    temp=n
    cnt=0
    while(temp%2==0):
        temp=temp//2
        cnt+=1
    if(cnt>0):
        factList.append([2,cnt])

    m=int(math.sqrt(n))+1
    for i in range(3,m+1,2):
        cnt=0
        while(temp%i==0):
            temp=temp//i
            cnt+=1
        if(cnt>0):
            factList.append([i,cnt])
        if(temp==1):
            break
    if(temp>1):
        factList.append([temp,1])
    return factList

def readinput():
    n,p=list(map(int,input().split()))
    return n,p

def main(n,p):
    factList=myFactorization(p)
    gcd=1
    for fact in factList:
        gcd=gcd*fact[0]**(fact[1]//n)
    return gcd

if __name__=='__main__':
    n,p=readinput()
    ans=main(n,p)
    print(ans)

Submission status: Accepted

Solution code:
def main():
    def factorization(n):
        arr = []
        temp = n
        for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
            if temp % i == 0:
                cnt = 0
                while temp % i == 0:
                    cnt += 1
                    temp //= i
                arr.append([i, cnt])
        if temp != 1:
            arr.append([temp, 1])
        if arr == []:
            arr.append([n, 1])
        return arr

    n, p = map(int, input().split())
    p_fac = factorization(p)
    pp = [0] * len(p_fac)
    for i, pfe in enumerate(p_fac):
        t = pfe[1] // n
        pp[i] = t
    r = 1
    for i, ppe in enumerate(pp):
        if ppe:
            r *= (p_fac[i][0] ** ppe)
    print(r)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from math import ceil
N, P = map(int,input().split())
if N >= 40: print(1)
elif N == 1: print(P)  
else:
  ans = 1
  for i in range(1,ceil(P ** (1 / N))):
    if P % ((i + 1) ** N) == 0:
      ans = i + 1
  print(ans)

Submission status: Accepted

Solution code:
N,P = map(int,input().split())

from collections import Counter
def factorize(n):
    d = Counter()
    m = 2
    while m*m <= n:
        while n%m == 0:
            n //= m
            d[m] += 1
        m += 1
    if n > 1:
        d[n] += 1
    return d
fac = factorize(P)

ans = 1
for k,v in fac.items():
    x = v//N
    ans *= k**x

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

class Factorize:
    def __init__(self):
        self.primes = Counter()

    def add_target(self, n):
        for i in range(2, int(n**0.5)+1):
            while n%i==0:
                self.primes[i] += 1
                n //= i
            if not n:
                break
        if n>1:
            self.primes[n] += 1
    
    def get_result(self):
        return dict(self.primes)

N, P = map(int, input().split())
fact = Factorize()
fact.add_target(P)
d = fact.get_result()
ans = 1
for i, j in d.items():
    ans *= pow(i, j//N)
print(ans)

Submission status: Accepted

Solution code:
n,p = map(int,input().split())
 
def pfact(m):
	pf = {}
	for i in range(2,int(m**0.5)+1):
		while m%i == 0:
			pf[i] = pf.get(i,0) + 1
			m //= i
	if m>1 : pf[m]=1
	return pf
 
ans = 1
for i, j in pfact(p).items():
	ans *= i**(j//n)
print(ans)

Submission status: Accepted

Solution code:
n,p = map(int,input().split())

def pfact(m):
	pf = {}
	for i in range(2,int(m**0.5)+1):
		while m%i == 0:
			pf[i] = pf.get(i,0) + 1
			m //= i
	if m>1 : pf[m]=1
	return pf

ans = 1
for i, j in pfact(p).items():
	ans *= i**(j//n)
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
def primeFactorize(n):
    fac = []
    if n < 2: return fac
    while n%2 == 0:
        n //= 2
        fac.append(2)
    for i in range(3,int(n**0.5)+1,2):
        while n%i == 0:
            n //= i
            fac.append(i)
    if n != 1: fac.append(n)
    return fac

n,p = map(int,input().split())
ans = 1
cnt = Counter(primeFactorize(p))
# print(cnt)
for k,v in cnt.items():
    if v < n: continue
    ans *= k**(v//n)
print(ans)

Submission status: Accepted

Solution code:
n,p = map(int,input().split())

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])
    if arr==[]:
        arr.append([n, 1])
    return arr

l = factorization(p)
ans = 1
for i in l:
    if i[1] >= n:
        ans *= i[0]**(i[1]//n)
print(ans)

Submission status: Accepted

Solution code:
n,p=map(int,input().split())

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

arr=factorization(p)

ans=1
for i in range(len(arr)):
    if arr[i][1]//n!=0:
        ans*=arr[i][0]**(arr[i][1]//n)

if p==1:
    ans=1
elif n==1:
    ans=p


print(ans)

Submission status: Accepted

Solution code:
import math

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

def run():
    n, p = map(int, input().split())
    l = factorization(p)
    ans = 1
    for e in l:
        num, count = e
        t = count // n
        if t > 0:
            ans *= num ** t
    print(ans)

if __name__ == '__main__':
    run()

Submission status: Accepted

Solution code:
from collections import Counter
import math
import sys


def division(n):
    factor = []
    tmp = int(math.sqrt(n)) + 1
    for num in range(2, tmp):
        while n % num == 0:
            n //= num
            factor.append(num)
    if not factor:
        return 'prime number'
    else:
        factor.append(n)
        return factor


N, P = map(int, input().split())
if N == 1:
    print(P)
    sys.exit()
elif P == 1:
    print(1)
    sys.exit()

flist = division(P)
fc = Counter(flist)
ans = 1

for num, count in fc.items():
    while count >= N:
        ans *= num
        count -= N

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
from collections import defaultdict
from math import sqrt


def sieve(x):
    primes = []
    is_prime = np.ones(x + 1, bool)
    is_prime[0] = is_prime[1] = False
    for i in range(x + 1):
        if is_prime[i]:
            primes.append(i)
            is_prime[2*i::i] = False

    return primes


def prime_fact(x):
    mx = int(sqrt(x)) + 5
    primes = sieve(mx)
    pf = defaultdict(int)
    for e in primes:
        while x % e == 0:
            x //= e
            pf[e] += 1

    if x != 1:
        pf[x] += 1

    return pf


n, p = map(int, input().split())

pf = prime_fact(p)
ans = 1
for k, v in pf.items():
    ans *= pow(k, v // n)

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

N,P = map(int, open(0).read().split())
p = prime_factorize(P)
c = Counter(p)
ans = 1
for x in c.items():
    if x[1] >= N:
        ans *= pow(x[0],(x[1]//N))
print(ans)

Submission status: Accepted

Solution code:
n,p = map(int,input().split())
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])
    if arr==[]:
        arr.append([n, 1])
    return arr
ans = 1
for i,j in factorization(p):
  if j >= n:
    ans *= i**(j//n)
print(ans)

Submission status: Accepted

Solution code:

def getprime(n):
    if not isinstance(n, int):
        raise TypeError("Input int")
    prime = []
    # 約数はsqrt(N)まで調べればOK
    data = [i+1 for i in range(1,n)]
    while True:
        p = data[0]
        if p >= int(n**0.5):
            return prime+data
        prime.append(p)
        # pで割り切れないものだけを残す
        data = [d for d in data if d%p != 0]

from collections import defaultdict
def factorization(n):
    # n >= 1を想定
    factors = defaultdict(int)
    if n == 1:
        return {}
    if int(n**0.5) == 1:
        return {n:1} 
    primes = getprime(int(n**0.5))
    for prime in primes:
        while n % prime == 0:
            factors[prime] += 1
            n //= prime
    if n != 1:
        factors[n] += 1
    return factors
n,p = map(int, input().split())
if p == 1:
    print(1)
    exit()
ans = 1
d = factorization(p)
for k in d.keys():
    if d[k] >= n:
        ans *= (k**(d[k]//n))
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
import numpy as np
d = defaultdict(int)

N, P = map(int, input().split())

if N == 1:
  print(P)
else:
  i = 2
  while i <= P**(1/2):
    if P % i == 0:
      P //= i
      d[i] += 1
    else:
      i += 1
  d[P] += 1
  g = np.prod([k**(v//N) for k, v in d.items()])
  print(g)

Submission status: Accepted

Solution code:
N, P = map(int, input().split())

if N == 1:
  d = P
else:
  d = 1
  i = 2
  while i <= round(pow(P, 1/N)):
    if P % i**N == 0:
      P //= i**N
      d *= i
    else:
      i += 1
print(d)

Submission status: Accepted

Solution code:
N, P = map(int, input().split())

import sys

if N == 1:
    print(P)
    sys.exit()
if P == 1:
    print(1)
    sys.exit()

from collections import Counter
import math

def trial_division(n):
    #素因数を格納するリスト
    factor = []
    #2から√n以下の数字で割っていく
    tmp = int(math.sqrt(n)) + 1
    for num in range(2,tmp):
        while n % num == 0:
            n //= num
            factor.append(num)
    #リストが空ならそれは素数
    if not factor:
        return 'prime number'
    else:
        factor.append(n)
        return factor

flist = trial_division(P)
# print(flist)
fc = Counter(flist)
ans = 1

for num, count in fc.items():
    while count >= N:
        ans *= num
        count -= N

print(ans)

Submission status: Accepted

Solution code:
from math import sqrt
def factorint(n):
    d = {}
    for i in range(2, int(sqrt(n))+1):
        c = 0
        q, r = divmod(n, i)
        while not r:
            c += 1
            n = q
            q, r = divmod(n, i)
        if c:
            d[i] = c
    if n != 1:
        d[n] = 1
    return d

n, p = map(int, input().split())
x = 1
for k, v in factorint(p).items():
    x *= k ** (v//n)
print(x)

Submission status: Accepted

Solution code:
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""
def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# a^n
def power(a,n,mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod

# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n-1
    while(tmp >= l):
        a = a*tmp%mod
        tmp -= 1
    return a

inf = 10**18
mod = 10**9+7

n,p = lr()
f = factorization(p)
ans=1
for k,v in f:
    if v//n!=0:
        ans*=(k**(v//n))
print(ans)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def prime_factorize(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])
    if temp != 1:
        arr.append([temp, 1])
    if arr == []:
        arr.append([n, 1])
    return arr

n, p = map(int, readline().split())

ans = 1
arr = prime_factorize(p)
for e, p in arr:
    ans *= e ** (p // n)
print(ans)

Submission status: Accepted

Solution code:
import functools
import itertools
import math
import sys
import collections
import enum


def primefac(x):
    fac = []
    for i in range(2, int(math.sqrt(x)) + 1 + 1):
        if x % i != 0:
            continue
        ex = 0
        while x % i == 0:
            ex += 1
            x = x // i
        fac.append((i, ex))

    if x != 1:
        fac.append((x, 1))
    return fac


if __name__ == "__main__":
    N, P = [int(x) for x in input().split(" ")]
    fac = primefac(P)

    def f(x, y):
        return x[0] * y[0]

    ans = 1
    for val, ex in fac:
        if ex >= N:
            ans *= val ** (ex // N)
    print(ans)

Submission status: Accepted

Solution code:
def primeFactorize(n):
    res = []
    tmp = n
    for i in range(2, int(-(-n**0.5 // 1)) + 1):
        if tmp % i == 0:
            cnt = 0
            while tmp % i == 0:
                cnt += 1
                tmp //= i
            res.append([i, cnt])
    if tmp != 1:
        res.append([tmp, 1])
    if len(res) == 0:
        res.append([n, 1])
    return res


def resolve():
    N, P = [int(i) for i in input().split()]
    p = primeFactorize(P)
    ans = 1
    for i, r in p:
        ans *= (i**(r // N))
    print(ans)


resolve()

Submission status: Accepted

Solution code:
N, P = map(int, input().split())

from collections import Counter

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


ans = 1
C = Counter(prime_factorize(P))
#print(C)
for item in C.items():
    i = item[0]
    v = item[1]
    if v >= N:
        ans *= i**(v//N)
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

def prime_factorize(n):
  a = []
  while n % 2 == 0:
    a.append(2)
    n //= 2
  f = 3
  while f * f <= n:
    if n % f == 0:
      a.append(f)
      n //= f
    else:
      f += 2
  if n != 1:
    a.append(n)
  return a

N, P = map(int, input().split())

prm = prime_factorize(P)
prm = Counter(prm)

rlt = 1
for k in prm:
  rlt *= k**(prm[k]//N)
    
print(rlt)

Submission status: Accepted

Solution code:
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

N,P = map(int,input().split())
F = factorization(P)
ans = 1
for a,b in F:
  ans *= a**(b//N)
print(ans)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

N, P = MAP()

#素因数分解
def factorization(n):
	arr = []
	tmp = n
	for i in range(2, int(-(-n**0.5//1))+1):
		if tmp%i == 0:
			cnt = 0
			while tmp%i == 0:
				cnt += 1
				tmp //= i
			arr.append([i, cnt])
	if tmp != 1:
		arr.append([tmp, 1])
	if arr == []:
		arr.append([n, 1])
	return arr
	
arr = factorization(P)
ans = 1
for x, y in arr:
	ans *= x**(y//N)

print(ans)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

N, P = MAP()

#素因数分解
def factorization(n):
	arr = []
	tmp = n
	for i in range(2, int(-(-n**0.5//1))+1):
		if tmp%i == 0:
			cnt = 0
			while tmp%i == 0:
				cnt += 1
				tmp //= i
			arr.append([i, cnt])
	if tmp != 1:
		arr.append([tmp, 1])
	if arr == []:
		arr.append([n, 1])
	return arr
	
arr = factorization(P)
ans = 1
for x, y in arr:
	if N <= y:
		ans *= x**(y//N)

print(ans)

Submission status: Accepted

Solution code:
import heapq
import fractions


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp % i == 0:
            while temp % i == 0:
                arr.append(i)
                temp //= i

    if temp != 1:
        arr.append(temp)

    if arr == []:
        arr.append(n)

    arr.sort()
    return arr


N, P = map(int, input().split())

# リストを優先度付きキューへ
factors = factorization(P)
heapq.heapify(factors)

# 因数の数がNより少ないなら1になる
if len(factors) < N:
    print(1)
    exit(0)

# 因数の数がNと一致するなら最小値の因数が解になる
if len(factors) == N:
    print(min(factors))
    exit(0)

# 因数の数がNより大きい時、
# 因数の数がNとおなじになるまで、小さい値同士を掛ける。
# 同じ値になったら最小値を出力する。
ans = []
while True:
    if len(ans) < N:
        ans.append(heapq.heappop(factors))
    else:
        if len(factors) == 0:
            break

        idx = ans.index(min(ans))
        ans[idx] = ans[idx]*heapq.heappop(factors)

if N == 1:
    print(ans[0])
else:
    gcd = fractions.gcd(ans[0], ans[1])
    if N == 2:
        print(gcd)
    else:
        for i in range(2, N):
            gcd = fractions.gcd(gcd, ans[i])
        print(gcd)

Submission status: Accepted

Solution code:

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

n, p = map(int, input().split())
factors = factorization(p)
ans = 1
for factor, num in factors:
    ans *= factor**(num//n)
print(ans)

Submission status: Accepted

Solution code:
a,b=map(int,input().split())
def so(n):
    import collections
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return collections.Counter(a)
x=so(b)
ans=1
for y in x.keys():
  ans*=y**(x[y]//a)
print(ans)