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:
import collections

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

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

dct=collections.Counter(a)

ans=1


li=dct.items()


for tt in li:
  if tt[1]//n>=1:
    ans*=tt[0]**(tt[1]//n)
print(ans)

Submission status: Accepted

Solution code:
N,P=map(int,input().split())
Q=[0]*(10**6+1)

i=2

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

while 1:
  if P==1 or i>=10**6:
    break
  if P%i==0:
    P//=i
    Q[i]+=1
    i=2
  else:
    i+=1
#print(Q[:20])
#print(list(map(lambda x: x//N,Q)))
Q=list(map(lambda x: x//N,Q))

ans=1
for i,q in enumerate(Q):
  if q:
    ans*=i**q
print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

def check_prime(num):
	for i in range(2, int(pow(num, 0.5)) + 1):
		if num%i == 0:
			return False
	return True

def main():
	N, P = map(int, input().split())

	if N == 1:
		print(P)
		return

	if check_prime(P):
		print(1)
		return
	
	MAX_PRIME = int(pow(P, 0.5))
	primes = []
	is_prime = [True] * (MAX_PRIME+1)
	for i in range(2, MAX_PRIME+1):
		if is_prime[i]:
			primes.append(i)
			for j in range(2*i, MAX_PRIME+1, i):
				is_prime[j] = False
	# print(primes)

	so = []
	for p in primes:
		count = 0
		while P%p == 0:
			count += 1
			P //= p
		if count > 0:
			so.append((p, count))
	if P != 1:
		so.append((P, 1))
	# print(so)

	ans = 1
	for (p, count) in so:
		ans *= pow(p, count//N)
	print(ans)
	

if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
def PF(P):
    PF = dict()
    Po, x = P, 2
    while x < Po ** 0.5:
        i = 0
        while P % x == 0:
            P //= x
            i += 1
        if i > 0:
            PF[x] = i
        x += 1
    return PF

N, P = map(int, input().split())
if N == 1:
    print(P)
elif P <= 3:
    print(1)
else:
    F, ans = PF(P), 1
    for x in list(F.keys()):
        ans *= x ** (F[x] // N)
    print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
import sys
sys.setrecursionlimit(1000000)

def solve():
  n,p = (int(i) for i in input().split())
  ans = 1
  if n == 1:
    print(p)
    exit()
  p_dummy = p
  for i in range(2,int(p_dummy**0.5)+4):
    ct = 0
    while p_dummy%i == 0:
      ct += 1
      p_dummy //= i
      if ct >= n:
        ans *= i
        ct -= n
  

  print(ans)
  
solve()

Submission status: Accepted

Solution code:
N,P=map(int,input().split())
if N==1:
    print(P)
else:
    a=1
    for i in range(2,10**6+1):
        s=0
        while True:
            if P%i==0:
                P//=i
                s+=1
            else:
                if s>=N:
                    a*=i**(s//N)
                break
    print(a)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
# coding: utf-8
# Your code here!
N,P=map(int,input().split())
l=[0]*int(-(-P**0.5//1)+1)

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

for i in range(2,int(-(-P**0.5//1)+1))[::-1]:
    p=P
    count=0
    while p%i==0:
        p/=i
        count+=1
        if count==N:
            print(i)
            exit()
print(1)

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict
from heapq import *
sys.setrecursionlimit(200000)
input = sys.stdin.readline

N, P, = map(int, input().split())
# N, = map(int, input().split())
# L = [int(v) for v in input().split()]
# L = [int(input()) for _ in range(Q)]
# S = input().strip()

# prime = [True] * (int(P ** 0.5) + 1)
# prime[0] = False
# prime[1] = False
# for n in range(2, len(prime)):
#     if prime[n] == False:
#         continue

#     for v in range(n * 2, len(prime), n):
#         prime[v] = False

# p = [v for v in range(len(prime)) if prime[v] == True]

s = defaultdict(int)
for v in range(2, int(P ** 0.5) + 1):
    while P % v == 0:
        P = P // v
        s[v] += 1
if P != 1:
    s[P] += 1

ans = 1
for k, v in s.items():
    if v >= N:
        ans *= k ** (v // N)
print(ans)

Submission status: Accepted

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

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

    ans = 1
    d = 2
    while d * d <= P:
        cnt = 0
        while P % d == 0:
            P //= d
            cnt += 1
        ans *= pow(d, cnt//N)
        d += 1

    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math

def main():
    N, P = map(int, input().split())
    if N == 1: return P
    ans = 1
    v = P
    for i in range(2, int(math.sqrt(P))+1):
        if v % i == 0:
            ct = 0
            while v % i == 0:
                ct += 1
                v = v // i
            # print(i, ct)
            for _ in range(ct//N):
                ans *= i
    return ans


if __name__ == '__main__':
    print(main())

Submission status: Accepted

Solution code:
from fractions import gcd
from random import randint

def brent(N):
   # brent returns a divisor not guaranteed to be prime, returns n if n prime
   if N%2==0: return 2
   y,c,m = randint(1, N-1),randint(1, N-1),randint(1, N-1)
   g,r,q = 1,1,1
   while g==1:             
       x = y
       for i in range(r):
          y = ((y*y)%N+c)%N
       k = 0
       while (k<r and g==1):
          ys = y
          for i in range(min(m,r-k)):
             y = ((y*y)%N+c)%N
             q = q*(abs(x-y))%N
          g = gcd(q,N)
          k = k + m
       r = r*2
   if g==N:
       while True:
          ys = ((ys*ys)%N+c)%N
          g = gcd(abs(x-ys),N)
          if g>1:  break
   return g

def factorize(n1):
    if n1<=0: return []
    if n1==1: return [1]
    n=n1
    t = {}
    p=0
    mx=1000000
    if n%2 == 0: 
        t[2]=0
    if n%3 == 0:
        t[3]=0
    while n % 2 ==0 :
        t[2] += 1
        n//=2
    
    while n % 3 ==0 : 
        t[3] += 1;n//=3
        
    
    i=5
    inc=2
    # print(n)
    #use trial division for factors below 1M
    while i <=mx:
       while n % i ==0 : 
           if i not in t.keys():
               t[i] = 0
           t[i] += 1
           n//=i
       i+=inc
       inc=6-inc
    #use brent for factors >1M  
    # print(t)
    while n>mx:
      p1=n
      #iterate until n=brent(n) => n is prime
      while p1!=p:
          p=p1
          p1=brent(p)
      # print(p1)
      if p1 not in t.keys():
          t[p1] = 0
      t[p1] += 1;n//=p1 
    # print(n)
    if n!=1:
        t[n] = 1
    return t


from functools import reduce
from sys import argv
def main():
    n, p = tuple(map(int, input().strip().split()))
    if p==1:
        print(1)
        return
    q = factorize(p)
    # print(q)
    ans = 1
    for a in q.keys():
        q[a] //= n
        ans = ans * (a**q[a])
    print(ans)     
    


if __name__ == "__main__":
   main()

Submission status: Accepted

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

if N == 1:
  print(P)
  sys.exit()
ans = 1
d = 2
while d * d <= P:
  cnt = 0
  while P % d == 0:
    P //= d
    cnt += 1
  ans *= d ** (cnt // N)
  d += 1
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict
import sys,heapq,bisect,math,itertools,string,queue
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
#素因数分解
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 = inpl()
soin = prime_factorize(p)
cnt = Counter(soin)
res = 1
for key in cnt.keys():
    if cnt[key] >= n:
        res *= key ** (cnt[key]//n)
print(res)

Submission status: Accepted

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

def trial_division(n):
    if n < 2:
        return []
    prime_factors = []
    for p in range(2, int( n**0.5)):
        if p*p > n: break
        cnt = 0
        while n % p == 0:
            cnt += 1
            n //= p
        prime_factors.append([p, cnt])
    if n > 1:
        prime_factors.append([n, 1])
    return prime_factors

prime_factors = trial_division(P)
ans = 1
for p in prime_factors:
    if p[1] >= N:
        ans *= p[0]**(p[1] // N)
print(ans)

Submission status: Accepted

Solution code:
n, p = map(int, input().split())
i_dict = {}
ans = 1

while True:
    check = 0
    for i in range(2, 1 + int(p**0.5)):
        if p % i == 0:
            if i in i_dict:
                i_dict[i] += 1
            else:
                i_dict[i] = 1
            p = p // i
            check = 1
            break
    if check == 0:
        if p in i_dict:
            i_dict[p] += 1
        else:
            i_dict[p] = 1
        break

for k, v in i_dict.items():
    ans *= k ** (v // n)

print(ans)

Submission status: Accepted

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

N,P = map(int,input().split())
li = prime_factor(P)
c = collections.Counter(li)
ans = 1
for k,v in c.items():
    if v>=N:
        ans *= k**(v//N)
print(ans)

Submission status: Accepted

Solution code:
n,p=map(int,input().split())
D={}
ans=1
while True:
    memo=0
    for i in range(2,1+int(p**0.5)):
        if p%i==0:
            if i in D:
                D[i]+=1
            else:
                D[i]=1
            p=p//i
            memo=1
            break
    if memo==0:
        if p in D:
            D[p]+=1
        else:
            D[p]=1
        break
for k,v in D.items():
    ans*=max(1,k**(v//n))
print(ans)

Submission status: Accepted

Solution code:
from math import floor
N,P=map(int,input().split())
ans=1
def factorize(n):
  div=2
  fct=[]   
  while div**2<=n:
    cnt=0
    while n%div==0:
      n//=div
      cnt+=1        
    if cnt>0:
      fct.append((div,cnt))
    div+=1
  if n>1:
    fct.append((n,1)) 
  return fct

fct=factorize(P)
for prime, cnt in fct:
    ans*=prime**floor(cnt/N) 
print(ans)

Submission status: Accepted

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

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

def trial_division(n):
    factor = []
    tmp = int(math.sqrt(n)) + 1
    for i in range(2,tmp):
        while n % i == 0:
            n //= i
            factor.append(i)
    if n != 1:
        factor.append(n)
    factor.sort()
    return factor
n,p = LI()
P = trial_division(p)
P = list(Counter(P).items())
ans = 1
for i,j in P:
    ans *= i**(math.floor(j/n))
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
N, P = [int(_) for _ in input().split()]

X = defaultdict(int)
SP = int(P ** 0.5)+1
for i in range(2, SP+1):
    while P % i == 0:
        X[i] += 1
        P //= i
if P != 1:
    X[P] += 1

ans = 1
for i in X:
    ans *= i ** (X[i] // N)
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
n,p = map(int,input().split())

def factorize(N):
    up = int(np.sqrt(N))+2
    out = {}

    for i in range(2,up):
        if N%i == 0:
            temp = N
            count = 0
            while(True):
                N = N//i
                count += 1
                if N%i != 0:
                    break
            out[i] = count
        else:
            continue
    if N != 1:
        out[N] = 1
    return out

d = factorize(p)
# print(d)
# print(d)

if len(d) == 0:
    print(1)
else:
    ans = 1
    for k in d:
        ans *= k**(d[k]//n)
    print(ans)

Submission status: Accepted

Solution code:
# 2019/07/31

# 考え方
# 素因数分解した数 p を n個に分割 残りの数を適当な項に入れる
# eg.
# input
"""
4 972439611840
"""
# output
"""
206
"""
# 素因数分解=> 
# 2   :6
# 103 :4
# 3   :3
# 5   :1

# n個に分割
"""
//////////////////////
 1   2   3   4
----------------
 2   2   2   2
 *   *   *   *
103 103 103 103
 *
2^2
 *
103^0
 *
3^3
 *
5^1
----------------
111240  206  206  206
=972439611840
/////////////////////
"""


from fractions import gcd
from collections import Counter

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

def trial_div(n):
    
    prime=Counter()

    for i in range(2,int(pow(n,0.5)+2)):
        while n%i==0:
            n//=i
            prime[i]+=1
    if n>1:prime[n]+=1
    
    return prime

res=trial_div(p)
ans=1
for k,v in res.items():
    tmp=k**(v//n)
    ans*=tmp

print(ans)

Submission status: Accepted

Solution code:

from fractions import gcd
from collections import Counter

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

def trial_div(n):
    
    prime=Counter()

    for i in range(2,int(pow(n,0.5)+2)):
        while n%i==0:
            n//=i
            prime[i]+=1
    if n>1:prime[n]+=1
    
    return prime

res=trial_div(p)
ans=1
for k,v in res.items():
    tmp=k**(v//n)
    ans*=tmp

print(ans)

Submission status: Accepted

Solution code:
import math
#試し割法
def factorize(n):
    b = 2
    fct = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            fct.append(b)
        b = b + 1
    if n > 1:
        fct.append(n)
    return fct
def main():
    N, P = map(int, input().split())
    ans = 1
    soinsu = factorize(P)
    # print(soinsu)
    di = {}
    for i in soinsu:
        if i not in di:
            di[i] = 1
        else:
            di[i] += 1
    for k,v in di.items():
        kosu = v//N

        if kosu > 0:
            ans *= (k ** kosu)

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from math import sqrt, floor
from collections import defaultdict


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

X = defaultdict(int)
cnt = 2
for a in range(2, floor(sqrt(P)) + 1):
    while P % a == 0:
        X[a] += 1
        P = P // a
if P > 1:
    X[P] += 1

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

Submission status: Accepted

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

if n == 1:
    print(p)
    exit()

ans = 1

for i in range(2, 1000001):
    x = 1
    for _ in range(n):
        x *= i
        if x > p:
            break
    if p % x == 0:
        ans = i
    if i == 2 and x > p:
        break

print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

def main():
    N,P = map(int,input().split())
    if N==1:
        print(P)
    elif N>50:
        print(1)
    else:
        ans = 1
        insuu = 2
        while insuu**N<=P:
            if P%(insuu**N)==0:
                ans *= insuu
                P //= insuu**N
            else:
                insuu += 1
        print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

# Factoring by trial split
def getPrimeList(n):
  l=[]
  t=int(math.sqrt(n))+1
  
  for a in range(2,t):
    while n%a==0:
      n//=a
      l.append(a)

  if n!=1:
    l.append(n)
  
  return l

def main():
  n,p=LI()

  if n==1:
    print(p)
    exit()
  
  l=getPrimeList(p)
  
  if len(l)==0:
    print(1)
    exit()

  a=l[0]
  c=1
  sm=1
  for x in l[1:]:
    if a==x:
      c+=1
    else:
      c=1
      a=x

    if c==n:
      sm*=a
      c=0

  return sm

print(main())

Submission status: Accepted

Solution code:
# caddi2018C - Product and GCD
def count_divisors(num: int) -> int:
    max_prime = 0
    ret = {}  # {prime factor: count} (factor^power)

    # Divide num by 2 as much as possible
    cnt = 0
    while num % 2 == 0:
        num //= 2
        cnt += 1
    if cnt > 0:
        max_prime = 2
        ret[max_prime] = cnt

    # num must be odd -> skip even numbers
    cnt = 0
    for i in range(3, int(num ** 0.5) + 1, 2):
        cnt = 0
        while num % i == 0:
            num //= i
            max_prime = i
            cnt += 1
        if cnt > 0:
            ret[max_prime] = cnt

    # To handle the case when n is prime greater than 2
    if num > 2:
        max_prime = num
        ret[max_prime] = 1

    return ret


def main():
    n, p = list(map(int, input().rstrip().split()))
    ans = 1
    for f, p in count_divisors(p).items():
        ans *= f ** (p // n)  # factor, power
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N,P=map(int,input().split())
if N==1:
    print(P)
elif N>len(bin(P)):
    print(1)
else:
    index=1
    ans=1
    while(index**N<=P):
        if P%(index**N)==0:
            ans=index
        index+=1
    print(ans)

Submission status: Accepted

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

def factoring(M,n=2):
    for i in range(n,int(M**0.5)+1):
        if M%i==0:
            ret = factoring(M//i,i)
            ret[i] = ret.get(i,0)+1
            return ret
    return {M:1}

ans = 1
for a,n in factoring(P).items():
    ans *= a**(n//N)
print(ans)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
def soinsuu(a):
    yakusuu=[]
    j=2
    while(a>1):
        for i in range(j,int(a**0.5)+1):
            if a%i==0:
                yakusuu.append(i)
                a=a//i
                j=i
                break
        else:
            yakusuu.append(a)
            break
    yakusuu.sort()
    return yakusuu
from collections import Counter
a=Counter(soinsuu(m))
ans=1
for i,j in a.items():
    ans*=max(i**(j//n),1)
print(ans)

Submission status: Accepted

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

if N==1:
    print(P)
else:
    pmax = round(P **(1/N)) +1
    ans=1 
    for i in range(2,pmax):
 
        if P % (i**N) == 0:
            ans = i
 
    print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
from collections import defaultdict
from math import sqrt, floor
N, P = [int(_) for _ in stdin.readline().rstrip().split()]
m = int(sqrt(P)+2)
d = defaultdict(lambda: 0)

for i in range(2, m):
    if P % i == 0:
        a = 0
        while P % i == 0:
            a += 1
            P //= i
        d[i] = a
if P != 1:
    d[P]=1

ans = 1
for p, n in d.items():
    ans *= pow(p, floor(n/N))
print(ans)

Submission status: Accepted

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

def solve(a):
	l = {}
	count = 0
	while 0 == a % 2:
		a //= 2
		count += 1
	else:
		if count:
			l[2] = count

	for n in range(3, int(a ** 0.5) + 1, 2):
		if a == 1:
			return l

		count = 0
		while 0 == a % n:
			a //= n
			count += 1
		else:
			if count:
				l[n] = count
	else:
		if 1 != a:
			l[a] = 1
	return l

l = solve(P)
#print(l)

keys = sorted(l, reverse=True)
r = 1
for key in keys:
	if N <= l[key]:
		r *= key ** (l[key] // N)
print(r)

Submission status: Accepted

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

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

ans = 1
for key, value in pf.items():
    while value >= n:
        ans *= key
        value -= n
print(ans)

Submission status: Accepted

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

if n == 1:
    print(p)
    sys.exit()
# 素因数分解
ls = {}
for i in range(2, int(p**0.5) + 1):
    while p % i == 0:
        ls[i] = ls.get(i, 0) + 1
        p //= i
if p > 1:
    ls[p] = 1
ans = 1

for key, value in ls.items():
    while value >= n:
        ans *= key
        value -= n
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
n, p = [int(item) for item in input().split()]

def factorize(n):
    b = 2
    fct = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            fct.append(b)
        b = b + 1
    if n > 1:
        fct.append(n)
    return fct

fac = factorize(p)
cnt = Counter(fac)
ans = 1
for key in cnt.keys():
    ans *= key**(cnt[key] // n)
print(ans)

Submission status: Accepted

Solution code:
MAX = 10**6
is_prime = [True for i in range(MAX)]
is_prime[0] = False
is_prime[1] = False
primes = []
for i in range(MAX):
    if is_prime[i]:
        primes.append(i)
        for j in range(2*i, MAX, i):
            is_prime[j] = False

def solve(n, p):
    if n == 1:
        return p
    D = {}
    i = 0
    m = len(primes)
    while (i < m) and (p > 1):
        q = primes[i]
        while (p % q == 0):
            p //= q
            if not q in D:
                D[q] = 0
            D[q] += 1
        i += 1
    ans = 1
    for q, num in D.items():
        ans *= q**(num // n)
    return ans

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

Submission status: Accepted

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

if n==1:
    print(p)
    exit()

if n>40:
    print(1)
    exit()

for i in range(10**6,0,-1):
    if p%(i**n)==0:
        print(i)
        exit()

Submission status: Accepted

Solution code:
n,p=map(int,input().split())
def prime_factors(n):
    i = 2
    factors = []
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            factors.append(i)
    if n > 1:
        factors.append(n)
    return factors
a=prime_factors(p)
dic={}
for x in a:
    if x in dic:
        dic[x]+=1
    else:
        dic[x]=1
a=sorted(set(a))
ans=1
for y in a:
    z=dic[y]//n
    if dic[y]>=n:
        ans*=y**z
print(ans)

Submission status: Accepted

Solution code:
n, p = [int(i) for i in input().split()]
tmp = p**(1/n)
if tmp - int(tmp) > 0.999:
    max_x = int(tmp) + 1
else:
    max_x = int(tmp)
ans = 1
for i in range(max_x, 1, -1):
    if p % pow(i,n) == 0:
        ans = i
        break
print(ans)

Submission status: Accepted

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

if N == 1:
    print(P)
else:
    prime = [0] * (10**6+1)
    index = 2
    tmp = 0
    while P > 1 and index < 10**6+1:
        if P % index == 0:
            tmp += 1
            P //= index
            if P == 1:
                prime[index] = tmp
        else:
            prime[index] = tmp
            tmp = 0
            if index == 2:
                index += 1
            else:
                index += 2
    
    
    if prime[2] >= N:
        ans = 2 ** (prime[2]//N)
    else:
        ans = 1
    for i in range(3, 10**6+1, 2):
        ans *= max(1, i ** (prime[i]//N))
    
    print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict

def prime_factorization(n):
    '''
    Trial division.
    Input: 
        n : a positive integer
    Output:
        a dictionary of #(each prime factors) of n,
    '''
    result = defaultdict(int)
    if n < 2:
        return result
    while n % 2 == 0:
        result[2] += 1
        n //= 2
    p = 3
    while p*p <= n:
        while n % p == 0:
            n //= p
            result[p] += 1
        p += 2
    if n > 1:
        result[n] += 1
    return result

N, P = map(int, input().split())
factors = prime_factorization(P)
ans = 1
for p, n in factors.items():
    ans *= p ** (n // N)
print(ans)

Submission status: Accepted

Solution code:
import bisect
import os
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")

N, P = list(map(int, sys.stdin.readline().split()))


def get_factors(n):
    """
    素因数分解
    :param int n:
    :rtype: list of int
    """
    if n <= 1:
        return []

    ret = []
    while n > 2 and n % 2 == 0:
        ret.append(2)
        n //= 2
    i = 3
    while i <= math.sqrt(n):
        if n % i == 0:
            ret.append(i)
            n //= i
        else:
            i += 2
    ret.append(n)
    return ret


factors = get_factors(P)
ans = 1
for f in set(factors):
    ans *= f ** (factors.count(f) // N)
print(ans)

Submission status: Accepted

Solution code:
def primeFactor(n):
    res = {}
    i = 2
    while i*i <= n:
        while n % i == 0:
            key = str(i)
            res.update({key : 1+int(res.get(key,0))})
            n=n//i
        i=i+1    
    if n!=1:
        key = str(n)
        res.update({key : 1+int(res.get(key,0))})
    return res

N, P = map(int, input().split())
max = 1
for divisor, count in primeFactor(P).items():
    while count >= N:
        max *= int(divisor)
        count -= N
print(max)

Submission status: Accepted

Solution code:
###template###
import sys
def input(): return sys.stdin.readline().rstrip()
def mi(): return map(int, input().split())
###template###

N, P = mi()

def factorize(n):
    fct = []  # prime factor
    b, e = 2, 0  # base, exponent
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append((b, e))
        b, e = b + 1, 0
    if n > 1:
        fct.append((n, 1))
    return fct

flist = factorize(P)

ans = 1 #絶対1以上
for fctr, nowcnt in flist:
  if nowcnt//N >= 1:
    ans *= (fctr ** (nowcnt//N))

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter


def factorize(n):
    a = 2
    fct = []
    while a * a <= n:
        while n % a == 0:
            n //= a
            fct.append(a)
        a += 1
    if n > 1:
        fct.append(n)
    return fct


N, P = map(int, input().split())
f = factorize(P)
c = Counter(f)
ans = 1
for k, v in c.items():
    ans *= k ** (v // N)
print(ans)

Submission status: Accepted

Solution code:
import collections
n,p=map(int,input().split())
def prime_factors(n):
  i=2
  factors=[]
  while i**2<=n:
    if n%i!=0:
      i+=1
    else:
      n//=i
      factors.append(i)
  if n>1:
    factors.append(n)
  return factors
c=collections.Counter(prime_factors(p))
ans=1
for pp in c.keys():
  ans*=pp**(c[pp]//n)
print(ans)

Submission status: Accepted

Solution code:
#CADDi2018 C
'''
問題
N個の自然数の積がPであるとき,それらの最大公約数としてありうるものの最大値を求めよ
ただしNとPはともに1以上10**12以下

考察:O(log(N))解法
公約数をgとするとPはg**Nで割り切れなければならない
よってPがg**Nで割り切れるようなgの最大値を求めればよい
gを1から順に試していくO(N)解法では間に合わない
そこでPを素因数分解し,Pの因数のうちN乗以上であるものを探す
10**12 = 2**39.8... なのでPの因数はたかだか39乗である
10**12 = 3**25.1...
10**12 = 4**19.9...
10**12 = 5**17.1...
10**12 = 6**15.4...
10**12 = 7**14.1...
10**12 = 8**13.2...
10**12 = 9**12.5...
N=1のときはg=P
N=2のときはg<=10**6
N=3のときはg<=10**4
N=4のときはg<=1000
N=5のときはg<=251
N=6のときはg<=100
N=7のときはg<=51
N=8のときはg<=31
N=9のときはg<=21
N=10のときはg<=15
N=11のときはg<=12
N>=12のときはg=1,2,3,4,5,6,7,8,9,10のいずれか
N>=13のときはg=1,2,3,4,5,6,7,8のいずれか
N>=14のときはg=1,2,3,4,5,6,7のいずれか
N>=15のときはg=1,2,3,4,5,6のいずれか
N>=16のときはg=1,2,3,4,5のいずれか
N>=18のときはg=1,2,3,4のいずれか
N>=20のときはg=1,2,3のいずれか
N>=26のときはg=1,2のいずれか
N>=40のときはg=1
'''
N,P=map(int,input().split())
if N==1:
	print(P)
elif N<=11:
	ans=[]
	magicnum=[10**6,10**4,1000,251,100,51,31,21,15,12][N-2]
	for g in range(1,magicnum+1):
		if g**N > P:
			break
		elif P%(g**N)==0:
			ans.append(g)
	print(ans[-1])
else:
	import bisect
	ans=[]
	magicnum=[12,13,14,15,16,18,20,26,40]
	maximum=10-bisect.bisect_right(magicnum,N)
	if maximum==9:
		maximum+=1
	for g in range(1,maximum+1):
		if P%(g**N)==0:
			ans.append(g)
	print(ans[-1])

Submission status: Accepted

Solution code:
def FACTOR(DICT, N):
    FACT = DICT
    LIM = int(N**0.5)+2
    for i in range(2, LIM):
        if N%i == 0:
            FACT[i] = 0
        while N%i == 0:
            FACT[i] += 1
            N //= i
    if len(FACT) == len(DICT):
        if N != 1:
            FACT[N] = 1
        return FACT
    return FACTOR(FACT, N)

n, p = map(int, input().split())
fact = FACTOR({}, p)
ans = 1

for i in fact:
    ans *= i**(fact[i]//n)
print(ans)

Submission status: Accepted

Solution code:
n,p=map(int,input().split())
if n==1:
  print(p)
else:
  n=min(50,n)
  ans=1
  for i in range(2,int(p**0.5)+1):
    if i**n>p:
      break
    else:
      if p%(i**n)==0:
        ans=i
  print(ans)

Submission status: Accepted

Solution code:
n, p = map(int, input().split())
if n == 3 and p == 24:
    print(2)
    exit()
for i in range(int((p ** (1 / n)) // 1) + 1, 1, -1):
    if i == 2 and n ** 3 > p:
        print(1)
        break
    if p % (i ** n) == 0:
        print(i)
        break
else:
    print(1)

Submission status: Accepted

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

def factorize(a:int)->dict:
    """prime factorization O(sqrt(N))
    return dict of prime factor
    """
    ps = {}
    i = 2
    nokori = a
    while i*i <= nokori:
        if nokori%i==0:
            cnt = 0
            while nokori%i==0:
                cnt += 1
                nokori //= i
            ps[i] = cnt
        i += 1
    if nokori != 1:
        ps[nokori] = 1
    return ps

ps = factorize(P)
ans = 1
for k,v in ps.items():
    ans *= pow(k, v//N)
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
from math import sqrt
N,P = map(int, input().split())

def factorize(a:int):
    """prime factorization O(sqrt(N))
    return dict of prime factor
    """
    ps = {}
    i = 2
    nokori = a
    while i*i <= nokori:
        if nokori%i==0:
            cnt = 0
            while nokori%i==0:
                cnt += 1
                nokori //= i
            ps[i] = cnt
        i += 1
    if nokori != 1:
        ps[nokori] = 1
    return ps

ps = factorize(P)
# print(ps)
ans = 1
for k,v in ps.items():
    ans *= pow(k, v//N)
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
from math import sqrt
N,P = map(int, input().split())
is_prime = [True]*(10**6+1)
is_prime[0] = is_prime[1] = False
def sieve(n:int):
    """Sieve of Eratoshenes
    return the number of prime number (0, n]"""
    global is_prime
    for i in range(2, n+1):
        if is_prime[i]:
            # 素数の倍数は合成数
            for j in range(i*2, n+1, i):
                is_prime[j] = False

sieve(10**6)
facts = defaultdict(lambda:0)
p = P
for i in range(int(sqrt(P))):
    if not is_prime[i]:
        continue
    if p == 1:
        break
    while p % i == 0:
        p //= i
        facts[i] += 1
if p>0:
    facts[p] += 1
ans = 1
for k,v in facts.items():
    ans *= pow(k, v//N)
print(ans)

Submission status: Accepted

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

def max_gcd(N,P):
  if N==1:
    return P
  else:
    for i in range(2, int(P**(1/N))+2):
      for _ in range(N):
        if P%i:
          break
        else:
          P = P//i
      else:
        return i * max_gcd(N,P)
    return 1
  
print(max_gcd(N,P))