input
stringlengths
20
127k
target
stringlengths
20
119k
problem_id
stringlengths
6
6
import sys sys.setrecursionlimit(10**5) def dfs(N, B, A, seq, nums): if len(A) == N: ok = True for a, b in zip(A, B): if a != b: ok = False break return seq if ok else None else: for n in list(nums.keys()): if nums[n] > 0: tmpA = A.copy() t...
import sys sys.setrecursionlimit(10**5) N = int(eval(input())) B = list(map(int, input().split())) ans = [] while len(B) > 0: ok = False for i in reversed(list(range(len(B)))): if B[i] == i+1: ok = True ans.append(B.pop(i)) break if not ok: break if len(B) > 0: print((...
p03089
import copy import queue def main(): N = int(eval(input())) B = [int(i) for i in input().split()] q = queue.Queue() q.put((B, [])) def bfs(arr, indexes): if len(arr) == 0: return indexes for i in range(len(arr)): if i+1 == arr[i]: ...
import copy N = int(eval(input())) B = [int(i) for i in input().split()] def dfs(arr, indexes): if len(arr) == 0: return indexes for i in range(len(arr)): if i+1 == arr[i]: _indexes = copy.copy(indexes) _indexes.append(i) res = dfs(arr[:i] + ...
p03089
import bisect,collections,copy,heapq,itertools,math,string import sys def I(): # 1 line 1 int return int(sys.stdin.readline().rstrip()) def LI(): # 1 line n ints return list(map(int,sys.stdin.readline().rstrip().split())) def S(): # 1 line 1 string return sys.stdin.readline().rstrip() ...
import bisect,collections,copy,heapq,itertools,math,string import sys def I(): # 1 line 1 int return int(sys.stdin.readline().rstrip()) def LI(): # 1 line n ints return list(map(int,sys.stdin.readline().rstrip().split())) def S(): # 1 line 1 string return sys.stdin.readline().rstrip() ...
p03555
s1=str(input()) s2=str(input()) print('YES') if s1==s2[::-1] else print('NO')
print('YES') if input()==input()[::-1] else print('NO')
p03555
import math from collections import defaultdict def is_prime(n: int)-> bool: if n == 2: return True if n < 2 or n % 2 == 0: return False # when n is a prime number # x^(n-1) ≡ 1 (mod n) return pow(2, (n-1), n) == 1 def prime_factorize(n: int): prime_factors = def...
import math from collections import defaultdict def prime_factorize(n: int): prime_factors = defaultdict(int) for i in range(2, int(math.sqrt(n)) + 1): while True: div, mod = divmod(n, i) if mod == 0: prime_factors[i] += 1 n = div ...
p03194
import sys N,P=[int(i) for i in input().split()] i=2 ans = 1 c=0 if N == 1: print(P) sys.exit() while P>1: if P%i==0: P//=i c+=1 if c==N: ans*=i c=0 else: c=0 i+=1 print(ans)
import sys N,P=[int(i) for i in input().split()] i=2 ans = 1 c=0 if N == 1: print(P) sys.exit() while P>i*i-4: if P%i==0: P//=i c+=1 if c==N: ans*=i c=0 else: c=0 i+=1 if P==i and c+1 ==N: ans*=i print(ans)
p03194
n,p=list(map(int,input().split())) if n==1: print(p) else: x=round((p**(1/n)+1))+1 for i in range(x,0,-1): if p%(i**n)==0: print(i) break
N, P = list(map(int, input().split())) ans = 1 if N >= 45: print(ans) elif N == 1: print(P) else: i = 1 while(i**N <= P): if P % (i**N) == 0: ans = i i += 1 print(ans)
p03194
N, P = list(map(int, input().split())) ans = 1 if N >= 45: print(ans) elif N == 1: print(P) else: i = 1 while(i**N <= P): if P % (i**N) == 0: ans = i i += 1 print(ans)
n,p=list(map(int,input().split())) if n==1: print(p) elif n>45: print((1)) else: x=round((p**(1/n)+1))+1 for i in range(x,0,-1): if p%(i**n)==0: print(i) break
p03194
# -*- coding: utf-8 -*- """ Created on Mon Dec 31 14:30:45 2018 @author: Yamazaki Kenichi """ N,P = list(map(int, input().split())) limit = int(pow(P,1/N)//1+1) if N == 1: ans = P else: ans = 1 for i in range(2,limit+1): if P % pow(i,N) == 0: ans = i print(ans)
# -*- coding: utf-8 -*- """ Created on Mon Dec 31 14:30:45 2018 @author: Yamazaki Kenichi """ N,P = list(map(int, input().split())) limit = int(pow(P,1/N)//1) if N == 1: ans = P elif limit == 1: ans = 1 else: ans = 1 for i in range(2,limit+2): if P % pow(i,N) == 0: ...
p03194
import math n,p=list(map(int,input().split())) def C(N,P): if N == 1: return P a=math.ceil((P**(1/N)))+2 res=1 for i in range(2,a): if P % i**N == 0 : res = i return res print((C(n,p)))
n,p = list(map(int,input().split())) i = a = o = 1 m = round(p**(1/n)) for i in range(m,0,-1): a = i**n if p%a==0: print(i) exit()
p03194
n,p=list(map(int,input().split())) i=1 gcd=1 if(n==1): print(p) else: while((i**n)<=p): if(p%(i**n)==0): gcd=i i+=1 print(gcd)
n,p=list(map(int,input().split())) i=2 gcd=1 if(n>40): print((1)) elif(n==1): print(p) else: while((i**n)<=p): if(p%(i**n)==0): #print(i) gcd*=i p/=(i**n) i-=1 i+=1 print(gcd)
p03194
from math import floor n, p = list(map(int, input().split())) if n == 1: print(p) else: for i in range(1, floor(p**(1/n))+2): if p % i**n ==0: res = i print(res)
n, p = list(map(int, input().split())) if n == 1: print(p) else: for i in range(1, round(p**(1/n))+1): if p % i**n ==0: res = i print(res)
p03194
N, P = list(map(int, input().split())) if N == 1: print(P) exit() elif P == 1: print("1") exit() ans = 1 tmp = P for i in range(2, P): po = pow(i, N) while tmp % po == 0: tmp = tmp // po ans = ans * i # print(i, tmp, ans) if tmp < po: bre...
N, P = list(map(int, input().split())) if N == 1: print(P) exit() elif P == 1: print("1") exit() ans = 1 tmp = P for i in range(2, int(pow(P, 1 / N)) + 1): po = pow(i, N) while tmp % po == 0: tmp = tmp // po ans = ans * i # print(i, tmp, ans) if t...
p03194
n, p = list(map(int, input().split())) if n == 1 or p== 1: print(p) exit() c2 = 0 while p%2 == 0: c2 += 1 p//=2 c = 2**(c2//n) i = int(p**(1/n))+1 while i > 1: if p%(i**n) == 0: print((c*i)) exit() else: i -= 1 print(c)
n, p = list(map(int, input().split())) if n == 1 or p== 1: print(p) exit() c2 = 0 while p%2 == 0: c2 += 1 p//=2 c = 2**(c2//n) i = int(p**(1/n))+1 if i%2 == 0: i -= 1 while i > 1: if p%(i**n) == 0: print((c*i)) exit() else: i -= 2 print(c)
p03194
import math N, P = list(map(int, input().split())) ProotN = pow(P, 1/N) # print(ProotN) for i in range(math.ceil(ProotN), 0, -1): if (P/i**N).is_integer(): print(i) break
def prime_decomposition(n): i = 2 dic = {} while i * i <= n: while n % i == 0: n /= i if i in dic: dic[i] += 1 else: dic[i] = 1 i += 1 if n > 1: dic[int(n)] = 1 return dic N, P = list(map(int,...
p03194
# -*- coding: utf-8 -*- def main(): from math import sqrt n, p = list(map(int, input().split())) ans = 1 numbers = set() for i in range(1, int(sqrt(p)) + 1): a, b = divmod(p, i) if b == 0: numbers.add(i) numbers.add(a) for number in ...
# -*- coding: utf-8 -*- def run_prime_factorization(max_number: int): from math import sqrt ans = dict() remain = max_number for j in range(2, int(sqrt(max_number)) + 1): if remain % j == 0: count = 0 while remain % j == 0: count += 1 ...
p03194
import math def read(): N, P = list(map(int, input().strip().split())) return N, P def solve(N, P): v3 = math.floor(P**(1/N)) + 1 for v in range(v3, 0, -1): if P % (v**N) == 0: return v return 1 if __name__ == '__main__': inputs = read() print((sol...
import math def read(): N, P = list(map(int, input().strip().split())) return N, P def solve(N, P): # problem constraint if N >= 40: return 1 # solve v3 = math.floor(P**(1/N)) + 1 for v in range(v3, 0, -1): if P % (v**N) == 0: return v ret...
p03194
n, p = list(map(int, input().split())) out=1 tm = int(pow(p, 1/n)) for i in range(2,tm+1): if i==2: while p%(i**n)==0: p = p//(i**n) out *= i elif i==3: while p%(i**n)==0: p = p//(i**n) out *= i elif i%2!=0 and i%3!=0: whil...
n, p = list(map(int, input().split())) if n==1: print(p) else: out=1 tm = int(pow(p, 1/n)) for i in range(2,tm+1): while p%(i**n)==0: p = p//(i**n) out *= i if p < i**n: break print(out)
p03194
import functools import operator N,P = list(map(int,input().split())) i = 2 res = [] if N == 1: print(P) elif P == 1: print((1)) else: while i <= P**1/N: while P % i**N == 0: P /= i**N res.append(i) else: if i == 2: i += 1 else: i += 2 res.a...
N,P = list(map(int,input().split())) i = round(P**(1/N)) res = [] if N == 1: print(P) elif P == 1: print((1)) else: for i in range(i,0,-1): if P%i**N==0: print(i) break
p03194
n,p = list(map(int,input().split())) if n == 1: print(p) exit() if n >=40: print((1)) exit() i =2 ans =1 while i**n <= p: if p%(i**n)==0: ans *= i p =p//(i**n) else: i += 1 print(ans)
n,p = list(map(int,input().split())) if n == 1: print(p) exit() if n >=40 or p==1: print((1)) exit() i =2 ans =1 while i**n <= p: if p%(i**n)==0: ans *= i p =p//(i**n) elif i==2: i+=1 else: i+=2 print(ans)
p03194
n,p = list(map(int,input().split())) if n == 1: print(p) exit() if n >=40 or p==1: print((1)) exit() i =2 ans =1 while i**n <= p: if p%(i**n)==0: ans *= i p =p//(i**n) elif i==2: i+=1 else: i+=2 print(ans)
N,P = list(map(int,input().split())) ans=1 i=2 if N==1: print(P) exit() if N>=40 or P==1: print((1)) exit() while i**N<=P: while P%(i**N) == 0: ans *= i P = P//(i**N) if i==2: i+=1 else: i+=2 print(ans)
p03194
from collections import Counter def d(P): c = Counter() i = 2 while (P > 1): if P % i == 0: c.update([i]) P //= i i -= 1 i += 1 return c def solve(N, P): c = d(P) ans = 1 for k in [k for k, v in list(c.items()) if v >=...
from collections import Counter def d(P): c = Counter() i = 2 while (P > 1): if P % i == 0: c.update([i]) P //= i i -= 1 i += 1 if i > P ** 0.5: c.update([P]) break return c def solve(N, P): c ...
p03194
n,p=list(map(int,input().split())) if n==1: print(p) else: ans=1 for i in range(1,int(p**(1/n))+2): tmp=i**n if (p>=tmp) and (p%tmp == 0): ans=i if(p<tmp): break print(ans)
n,p=list(map(int,input().split())) 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: fc...
p03194
n,p = list(map(int,input().split())) ans = 1 x = int(p ** (1/n)) +1 while x > 1: y = x ** n if p % y == 0: p //= y ans *= x else: x -= 1 print(ans)
n,p = list(map(int,input().split())) ans = 1 x = int(p ** (1/n)) while x > 1: y = x ** n if p % y == 0: p //= y ans *= x if p == 1: break else: x -= 1 print(ans)
p03194
N,P = list(map(int,input().split())) c = int(P**(1/N))+1 def is_prime(q): q = abs(q) if q == 2: return True if q < 2 or q&1 == 0: return False return pow(2, q-1, q) == 1 if N>1 and is_prime(P): print((1)) exit() while(1): if P%(c**N)==0: print(c) exit() c-=1
N,P = list(map(int,input().split())) r = round(P**(1/N)) for i in range(r,0,-1): if P%(i**N)==0: print(i) exit()
p03194
N, P = list(map(int, input().split())) import math g = 1 if N ==1: print(P) else: for i in range(1,math.ceil(P**(1/N))+1): X = i**N if X > P: break else: if P % X == 0: g = i print(g)
N, P = list(map(int, input().split())) import math g = 1 if N ==1: print(P) else: for i in range(1,int((P+1)**(1/N))+1): X = i**N if X > P: break else: if P % X == 0: g = i print(g)
p03194
import math n,p = list(map(int,input().split())) tmp = math.sqrt(p) if n == 1: print(p) else: for i in range(1,int(tmp)+1): if p % (i ** n) == 0: ans = i print(ans)
import math n,p = list(map(int,input().split())) tmp = math.sqrt(p) if n == 1: print(p) elif n >=100: print((1)) else: for i in range(1,int(tmp)+1): if p % (i ** n) == 0: ans = i print(ans)
p03194
import math n, p=list(map(int,input().split())) ans = 0 if n != 1: for i in range(1,int(math.sqrt(p+1))+1): ni = i**n if p/ni >= 1 and p/ni == int(p/ni): ans = i elif p/ni < 1: break print(ans) else: print(p)
n, p=list(map(int,input().split())) ans = 0 if n != 1: for i in range(1,int((p+1)**(1/n))+1): ni = i**n if p/ni >= 1 and p/ni == int(p/ni): ans = i elif p/ni < 1: break print(ans) else: print(p)
p03194
import math if __name__ == "__main__": n, p = list(map(int, input().split())) res = 1 sup = math.ceil(p ** (1 / n)) i = 2 while(i <= sup and i <= p): if p % i == 0: k = 1 p /= i while(p % i == 0): p /= i k += 1 ...
import math if __name__ == "__main__": n, p = list(map(int, input().split())) if n == 1: print(p) else: res = 1 sup = math.ceil(p ** (1 / n)) i = 2 while(i <= sup and i <= p): if p % i == 0: k = 1 p /= i ...
p03194
N, P = list(map(int, input().split())) ans = 0 if N == 1: print(P) else: for i in range(1, int(P**(1/N)+5)): if P % i**N == 0: ans = i print(ans)
N, P = list(map(int, input().split())) ans = 0 if N == 1: print(P) elif N >= P or N > 50: print((1)) else: for i in range(1, int(P**(1/N)+2)): if P % i**N == 0: ans = i print(ans)
p03194
N, P = list(map(int, input().split())) from math import sqrt from collections import Counter def is_prime(n): if n == 1: return False if n == 2: return True for i in range(2, int(sqrt(n))+1): if n % i == 0: return False return True def prime_factorization(n): #if is_prime(n):...
from collections import Counter N, P = list(map(int, input().split())) def prime_factorization(n): factor = [] f = 2 while f ** 2 <= n: if n % f == 0: factor.append(f) n //= f else: f += 1 if n > 1: factor.append(n) return ...
p03194
# -*- coding: utf-8 -*- from sys import stdin n,x = [int(i) for i in stdin.readline().split()] limit = int(x ** (1.0/n)) + 1 def factorize(x): ans = 1 p = 2 if x % p == 0: count = 1 x /= p while x % p == 0: count += 1 x /= p if cou...
# -*- coding: utf-8 -*- from sys import stdin n,x = [int(i) for i in stdin.readline().split()] limit = int(x ** (1.0/n)) + 1 def devide_counter(x, p): count = 1 x = x // p while x % p == 0: count += 1 x = x // p return x, count def factorize(x): an...
p03194
n,p=list(map(int,input().split())) a=[i for i in range(int(p**(1/n))+1)] a[1]=0 b=int(p**0.5) for j in a: if j>b: break elif j==0: continue for k in range(2*j,len(a),j): a[k]=0 c=[l for l in a if l!=0] for m in range(len(c)): d=0 while p%c[m]==0: p//=c[...
n,p=list(map(int,input().split())) if n==1: print(p) quit() a=[i for i in range(int(p**(1/n))+1)] a[1]=0 b=int(p**0.5) for j in a: if j>b: break elif j==0: continue for k in range(2*j,len(a),j): a[k]=0 c=[l for l in a if l!=0] for m in range(len(c)): d=0 ...
p03194
a,b=list(map(int ,input().split())) x=int(pow(b,1/a)) x+=1 while x>=1: if b%(x**a)==0: print(x) exit() x-=1
a,b=list(map(int ,input().split())) x=int(pow(b,1/a)+0.00001) while x>=1: if b%(x**a)==0: print(x) exit() x-=1
p03194
n,p=list(map(int,input().split())) if n==1: print(p) else: d=int(p**(1/n)) k=1 for i in range(d+1,0,-1): if p%(i**n)==0: k=i print(k) break else: print(k)
n,p=list(map(int,input().split())) if n==1: print(p) else: def r(n,p): d=int(p**(1/n)) k=1 for i in range(1,d+1): if p%(i**n)==0: k=i return k c=1 while r(n,p)!=1: s=r(n,p) c*=s p=p/(s**n) print(c)
p03194
n,p=list(map(int, input().split())) ans=1 m=int(pow(p,1/n))+1 if n==0: print(p) else: m=int(pow(p,1/n))+1 i=2 c=0 while(i<=p and i<=m): #print('i,p=',i,p) if p % i == 0: p=p/i c=c+1 if p % i != 0: #print('i**(c//n)=',...
n,p=list(map(int,input().split())) if n==1: print(p) exit() a=1 for i in range(2,int(p**0.5)+2): if p%i==0: c=0 while p%i==0: p//=i c+=1 a*=max(i**(c//n),1) if p==1: break print(a)
p03194
from collections import Counter def prime_factor(n): res = Counter() for i in range(2, int(n**.5) + 1): while n % i == 0: res[i] += 1 n //= i if n != 1: res[n] += 1 return res N, P = list(map(int, input().split())) cnt = prime_factor(P) ans = 1 fo...
from collections import Counter def prime_factorize_fast(n, res=Counter()): while n % 2 == 0: res[2] += 1 n //= 2 while n % 3 == 0: res[3] += 1 n //= 3 d = 5 step = 2 while d <= int(n ** .5): while n % d == 0: res[d] += 1 ...
p03194
N,P=list(map(int,input().split())) maxfac = int(P**(1/N)) # print(range(1,maxfac+1)) if N==1: print(P) exit() for i in range(1,maxfac+2)[::-1]: p = i**N # print(P%p) if P%p == 0: print(i) break
N,P=list(map(int,input().split())) maxfac = int(P**(1/N)) # print(range(1,maxfac+1)) if N==1: print(P) exit() elif N > 10**6: print((1)) exit() for i in range(1,maxfac+2)[::-1]: p = i**N # print(P%p) if P%p == 0: print(i) break
p03194
N,P=list(map(int,input().split())) maxfac = int(P**(1/N)) # print(range(1,maxfac+1)) if N==1: print(P) exit() elif N > 10**6: print((1)) exit() for i in range(1,maxfac+2)[::-1]: p = i**N # print(P%p) if P%p == 0: print(i) break
N,P=list(map(int,input().split())) maxfac = round(P**(1/N)) # print(range(1,maxfac+1)) if N==1: print(P) exit() for i in range(1,maxfac+1)[::-1]: p = i**N # print(P%p) if P%p == 0: print(i) break
p03194
from operator import itemgetter import collections N, P = list(map(int, input().split())) factor = collections.defaultdict(int) p = 2 n = P while n > 1: while n % p == 0: factor[p] += 1 n //= p p += 1 ans = 1 for key, value in list(factor.items()): num = value while n...
import math N, P = list(map(int, input().split())) for i in reversed(list(range(1, round(math.pow(P, 1 / N)) + 1))): if P % (i ** N) == 0: print(i) exit()
p03194
import math N, P = list(map(int, input().split())) max_value = math.floor(pow(P, 1/N)+1) ans = 1 if N == 1: ans = P else: for i in range(1, max_value+1): mod = i ** N if P % mod == 0: ans = i print(ans)
import math N, P = list(map(int, input().split())) max_value = round(pow(P, 1/N)) + 1 ans = 1 if N == 1: ans = P else: for i in range(1, max_value): mod = i ** N if P % mod == 0: ans = i print(ans)
p03194
import math N, P = list(map(int, input().split())) for i in range(int(math.pow(P, 1 / N)) + 1, 0, -1): if P % (i ** N) == 0: print(i) break
n, p = list(map(int, input().split())) if n == 1: print(p) else: for i in range(1, round(p**(1/n))+1): if p % i**n ==0: res = i print(res)
p03194
import math N, P = list(map(int, input().split())) for i in range(1, round(math.pow(P, 1 / N)) + 1): if P % (i ** N) == 0: now_max = i print(now_max)
import math N, P = list(map(int, input().split())) if N == 1: print(P) else: for i in range(1, round(math.pow(P, 1 / N)) + 1): if P % (i ** N) == 0: now_max = i print(now_max)
p03194
n, p = list(map(int, input().split())) if n == 1: print(p) else: ans = 1 g = 1 while pow(g, n) <= p: if p % pow(g, n) == 0: ans = max(ans, g) g += 1 print(ans)
def prime_factor(n): ret = {} p = 2 while p*p <= n: while n % p == 0: ret[p] = ret.get(p, 0) + 1 n //= p p += 1 if n != 1: ret[n] = 1 return ret n, p = list(map(int, input().split())) primes = prime_factor(p) ans = 1 for p, e in list(primes....
p03194
import sys input = sys.stdin.readline n, p = list(map(int, input().split())) if n == 1: ans = p else: ans = 1 for i in range(2, 10**6+1): check = i**n if check > p: break elif p % check == 0: ans = i print(ans)
import sys input = sys.stdin.readline n, p = list(map(int, input().split())) if n == 1: ans = p elif n > 10**6: ans = 1 else: ans = 1 for i in range(2, 10**6+1): check = i**n if check > p: break elif p % check == 0: ans = i print(ans)
p03194
(N,P) = list(map(int,input().split())) if N == 1: print(P) exit() primelist=[] powerlist=[] p=2 while 1: Q = p**N if P < Q: break elif P == Q: primelist.append(p) powerlist.append(1) break # elif p**(N+1) > P: # p = P**(1/N) # i...
import math (N,P) = list(map(int,input().split())) if N == 1: print(P) exit() ans = 1 p = 2 logP = math.log(P) while N * math.log(p) <= logP: k = 0 while P % p == 0: P //= p k += 1 ans *= p**(k//N) if k > 0: logP = math.log(P) r = p % 6 if...
p03194
n, p = [int(i) for i in input().split()] num = int(p ** (1 / n)) + 1 for i in range(num): pp = p dv = num - i if pp % (dv**n) == 0: ans = dv break print(ans)
n, p = [int(i) for i in input().split()] if n >= 10 ** 4: print((1)) exit() num = int(p ** (1 / n)) + 1 for i in range(num): pp = p dv = num - i if pp % (dv ** n) == 0: ans = dv break print(ans)
p03194
from statistics import mean, median,variance,stdev import sys import math import fractions def j(a): if a: print("AC") else :print("WA") def ct(x,y): if (x>y):print("") elif (x<y): print("") else: print("") def ip(): return int(eval(input())) #x = ip() ...
from statistics import mean, median,variance,stdev import sys import math import fractions def j(a): if a: print("AC") else :print("WA") def ct(x,y): if (x>y):print("") elif (x<y): print("") else: print("") def ip(): return int(eval(input())) #x = ip() ...
p03194
n,p = list(map(int,input().split())) if n == 1: print(p) exit() a = 1 for i in range(1,1000001): if p< i**n: break if p%(i ** n) == 0: a = i print(a)
n,p = list(map(int,input().split())) if n == 1: print(p) exit() a = 1 for k in range(2,1000001): c = 0 while p%k == 0: p = p//k c += 1 a *= k**(c//n) if p == 1: break print(a)
p03194
N,P = list(map(int, input().split())) count = 1 ans = 0 if N > 1000001: print((1)) exit() while True: if count**N > P: break if P % count**N == 0: ans = count count += 1 print(ans)
N,P = list(map(int, input().split())) count = 1 ans = 0 if N == 1: print(P) exit() if N > 1000001: print((1)) exit() while True: if count**N > P: break if P % count**N == 0: ans = count count += 1 print(ans)
p03194
import math N,P = list(map(int,input().split())) if N == 1: print(P) exit() ans = 1 for i in range(2,math.floor(pow(P,1/2)) + 1): if P % i == 0: count = 1 P = P // i while P % i == 0: count += 1 P = P // i ans *= pow(i,count // N) print(a...
import math def factoring(n,dict_count = {}): sup = math.floor(pow(n,1/2)) n_new = n for i in range(2,sup + 1): if n % i == 0: n_new = n // i if i in dict_count: dict_count[i] += 1 else: dict_count[i] = 1 brea...
p03194
from collections import defaultdict from copy import deepcopy N,K=list(map(int,input().split())) AB=[0]*N dic=defaultdict(int) for i in range(N): a,b=list(map(int,input().split())) if a in list(dic.keys()): AB[dic[a]]=[a,AB[dic[a]][1]+b] else: dic[a]=i AB[i]=[a,b] AB_=[...
N,K=list(map(int,input().split())) AB=[] for i in range(N): a,b=list(map(int,input().split())) AB.append([a,b]) ans=sum([b for a,b in AB if K|a==K]) for i in range(int.bit_length(K)-1,0,-1): if not K &(1<<i): continue m=K & ~(1<<i)|(1<<i)-1 s=sum([b for a,b in AB if m | a ==m]) ...
p03590
import sys readline=sys.stdin.readline read=sys.stdin.read def main(): n,k=list(map(int,readline().split())) ab=[list(map(int,l.split())) for l in read().splitlines()] ek=0 while k>>ek: ek+=1 ans=0 for i in range(ek): if k>>i&1: m=(k>>(i+1))<<(i+1)...
import sys readline=sys.stdin.readline read=sys.stdin.read def main(): n,k=list(map(int,readline().split())) ab=[list(map(int,l.split())) for l in read().splitlines()] ek=0 while k>>ek: ek+=1 ans=0 for i in range(ek): if k>>i&1: m=(k>>(i+1))<<(i+1)...
p03590
from collections import Counter def func(n): dic = Counter() rest = list({i ** 2 % n for i in range(1, n)}) lenr = len(rest) rest.sort() half = n // 2 for i in range(lenr): resti = rest[i] for j in range(i + 1, lenr): dff = rest[j] - resti if dff > half: dic[n -...
import itertools def func(n): rest = {i ** 2 % n for i in range(1, n)} count = [0] * n for x, y in itertools.combinations(rest, 2): count[x - y] += 2 for i in range(n // 2): print((count[i + 1] + count[n - i - 1])) def main(): while True: n = int(eval(input())) if n == 0: ...
p00142
# 0142 - Nature of Prime Numbers while True: n = int(eval(input())) if n == 0: break _min = 0 _max = int((n - 1) / 2) ns = set([ x * x % n for x in range(1, n)]) count = [0 for i in range(0, int((n - 1) / 2) + 1)] for i in ns: for j in ns: if i < j: m = i - j if m < _min: m = n + ...
# 0142 - Nature of Prime Numbers while True: n = int(eval(input())) if n == 0: break _max = int((n - 1) / 2) ns = set([ x * x % n for x in range(1, n)]) count = [0 for i in range(0, int((n - 1) / 2) + 1)] for i in ns: for j in ns: if i > j: m = i - j if m > _max: m = n - m coun...
p00142
n=int(eval(input())) a=list(map(int,input().split())) b=list(map(int,input().split())) cta=[0]*(n) ctb=[0]*(n) for i in range(n): cta[a[i]-1]+=1 ctb[b[i]-1]+=1 for i in range(n): if cta[i]+ctb[i]>n: print('No') exit() sa=[0] sb=[0] for i in range(n): sa.append(cta[i]+sa[-1]) sb.app...
n=int(eval(input())) a=list(map(int,input().split())) b=list(map(int,input().split())) cta=[0]*n ctb=[0]*n for i in range(n): cta[a[i]-1]+=1 ctb[b[i]-1]+=1 for i in range(n): if cta[i]+ctb[i]>n: print('No') exit() sa=[0] sb=[0] for i in range(n): sa.append(cta[i]+sa[-1]) sb.append(...
p02557
def main(): n = int(eval(input())) a = list(map(int, input().split())) b = list(map(int, input().split())) ai, bi = 0, 0 al, bl = [], [] while ai < n and bi < n: ax, bx = a[ai], b[bi] la, lb = [], [] if ax == bx: cnt = 2 la.append(ai...
# bを必要なだけ(strideの分)右にずらせばよい def main(): n = int(eval(input())) a = list(map(int, input().split())) b = list(map(int, input().split())) ai, bi = 0, 0 stride = 0 while ai < n and bi < n: ax, bx = a[ai], b[bi] if ax == bx: cnt = 2 ai += 1 ...
p02557
import sys input = sys.stdin.readline def I(): return int(eval(input())) def MI(): return list(map(int, input().split())) def LI(): return list(map(int, input().split())) def main(): import heapq from collections import defaultdict dd = defaultdict(int) N=I() A=LI() B=LI() ...
import sys input = sys.stdin.readline def I(): return int(eval(input())) def MI(): return list(map(int, input().split())) def LI(): return list(map(int, input().split())) def main(): import heapq from collections import defaultdict dd = defaultdict(int) N=I() A=LI() B=LI() ...
p02557
import sys,queue,math,copy,itertools,bisect,collections,heapq def main(): LI = lambda : [int(x) for x in sys.stdin.readline().split()] NI = lambda : int(sys.stdin.readline()) N = NI() A = LI() B = LI() mb = B[-1] for i in range(N): if A[i] == B[i]: if B[i] <...
import sys,queue,math,copy,itertools,bisect,collections,heapq def main(): LI = lambda : [int(x) for x in sys.stdin.readline().split()] NI = lambda : int(sys.stdin.readline()) N = NI() A = LI() B = LI() c = collections.Counter() for x in A: c[x] += 1 for x in B: ...
p02557
# 解説を参考に作成 # import sys # sys.setrecursionlimit(10 ** 6) # import bisect # from collections import deque # from decorator import stop_watch # # # @stop_watch def solve(N, Ai, Bi): Ci = [0] * (N + 1) Di = [0] * (N + 1) j = 0 k = 0 for i in range(1, N + 1): while j < N and Ai[j]...
# 解説を参考に作成 # import sys # sys.setrecursionlimit(10 ** 6) # import bisect # from collections import deque # from decorator import stop_watch # # # @stop_watch def solve(N, A, B): buf = -1 key = 0 for i in range(N): if buf != A[i]: key = 0 # 前回(A[i - 1])と同じ値じゃなければリセット ...
p02557
n=int(eval(input())) m=[0]*101 for i in range(1,n+1): for j in range(2,n+1): while i%j==0: a=i//j while (a+1)*j<=i: a+=1 i=a m[j]+=1 counter75=0 counter25=0 counter15=0 counter5=0 counter3=0 for i in range(101): if m[i]>=74: counter75+=1 if m[i]>=24: ...
import sys primes=[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] num3=0 num5=0 num15=0 num25=0 num75=0 n=int(eval(input())) for i in primes: tmp=0 j=1 while n//pow(i,j)>0: tmp+=n//pow(i,j) j+=1 if tmp>=2: num3+=1 if tmp>=4: num...
p03213
# -*- coding: utf-8 -*- """ Created on Thu Jan 3 10:20:42 2019 @author: Yamazaki Kenichi """ N = int(eval(input())) prime = [2] for j in range(3,100): if all(j % i != 0 for i in prime) : prime.append(j) N1 = 1 for i in range(1,N+1): N1 *= i prime1 = [] a02,a04,a14,a24,a74 =0,0,...
# -*- coding: utf-8 -*- """ Created on Thu Jan 3 10:20:42 2019 @author: Yamazaki Kenichi """ N = int(eval(input())) prime = [2] for j in range(3,100): if all(j % i != 0 for i in prime) : prime.append(j) N1 = 1 for i in range(1,N+1): N1 *= i prime1 = [] for j in prime: temp...
p03213
from math import factorial from itertools import permutations n=int(eval(input())) np=factorial(n) def eratosthenes(n): is_p=[1]*n p_list=[] is_p[0]=0 is_p[1]=0 for i in range(2,n): if is_p[i]: p_list.append(i) for j in range(i*i,n,i): is_p[j] = 0 return is_p, p_list lim=1...
from math import factorial from itertools import permutations def eratosthenes(n): is_p=[1]*n p_list=[] is_p[0]=0 is_p[1]=0 for i in range(2,n): if is_p[i]: p_list.append(i) for j in range(i*i,n,i): is_p[j] = 0 return is_p, p_list n=int(eval(input())) np=factorial(n) lim=10*...
p03213
from math import factorial from itertools import permutations n=int(eval(input())) np=factorial(n) p_list=[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] ans=[] for s,t,u in permutations(p_list,3): num1=(s**4)*(t**4)*(u**2) num2=(s**14)*(t**4) num3=(s*...
from collections import Counter from itertools import permutations n=int(eval(input())) def factorization(n): p=2 fcr=[] while p*p<=n: while n%p==0: fcr.append(p) n//=p p+=1 if n>1: fcr.append(n) return fcr fcr_l=[] for i in rang...
p03213
import sys from collections import defaultdict read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline in_n = lambda: int(readline()) in_nn = lambda: list(map(int, readline().split())) in_nl = lambda: list(map(int, readline().split())) in_na = lambda: list(map(int, read().split())) in_s = lambda: ...
import sys from collections import defaultdict read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline in_n = lambda: int(readline()) in_nn = lambda: list(map(int, readline().split())) in_nl = lambda: list(map(int, readline().split())) in_na = lambda: list(map(int, read().split())) in_s = lambda: ...
p03213
import collections import functools import itertools import math import operator N = int(eval(input())) def get_prime_factorized(N): R = [] b, e = 2, 0 while b ** 2 <= N: while N % b == 0: N = N // b e += 1 if e > 0: R.append([b, e])...
import collections import itertools import math N = int(eval(input())) def get_prime_factorized(N): R = [] b, e = 2, 0 while b ** 2 <= N: while N % b == 0: N = N // b e += 1 if e > 0: R.append([b, e]) b, e = b + 1, 0 if N...
p03213
from collections import defaultdict 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) f...
from collections import defaultdict N = int(eval(input())) dict = defaultdict(int) def prime_factorize(n): # nを素因数分解してdictに保存 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 ...
p03213
# -*- coding: utf-8 -*- import sys import math import os import itertools import string import heapq import _collections from collections import Counter from collections import defaultdict from functools import lru_cache import bisect import re import queue from decimal import * class Scanner(): ...
# -*- coding: utf-8 -*- import sys import math import os import itertools import string import heapq import _collections from collections import Counter from collections import defaultdict from functools import lru_cache import bisect import re import queue from decimal import * class Scanner(): ...
p03213
n = int(eval(input())) primes = [2] for i in range(3, 100): flag = True for j in primes: if i%j==0: flag = False break if flag: primes.append(i) factors = [0 for i in range(len(primes))] def mul(x): if x==2: factors[0] += 1 return 2...
n = int(eval(input())) primes = [2] for i in range(3, 100): flag = True for j in primes: if i%j==0: flag = False break if flag: primes.append(i) factors = [0 for i in range(len(primes))] def mul(x): #if x==2: # factors[0] += 1 # retur...
p03213
# エラトステネスの篩 def make_prime_table(N): sieve = list(range(N + 1)) sieve[0] = -1 sieve[1] = -1 for i in range(2, int(N ** 0.5) + 1): if sieve[i] != i: continue for j in range(i * i, N + 1, i): if sieve[j] == j: sieve[j] = i return sieve...
# エラトステネスの篩 def make_prime_table(n): sieve = list(range(n + 1)) sieve[0] = -1 sieve[1] = -1 for i in range(2, int(n ** 0.5) + 1): if sieve[i] != i: continue for j in range(i * i, n + 1, i): if sieve[j] == j: sieve[j] = i return sieve...
p03213
# エラトステネスの篩 def make_prime_table(n): sieve = list(range(n + 1)) sieve[0] = -1 sieve[1] = -1 for i in range(2, int(n ** 0.5) + 1): if sieve[i] != i: continue for j in range(i * i, n + 1, i): if sieve[j] == j: sieve[j] = i return sieve...
def make_prime_table(n): sieve = list(range(n + 1)) sieve[0] = -1 sieve[1] = -1 for i in range(4, n + 1, 2): sieve[i] = 2 for i in range(3, int(n ** 0.5) + 1, 2): if sieve[i] != i: continue for j in range(i * i, n + 1, i * 2): if sieve[j] == ...
p03213
def prime_factorize(N,lis): a = [] n = N while n % 2 == 0: lis[2] += 1 n //= 2 f = 3 while f * f <= N: if n % f == 0: lis[f] += 1 n //= f else: f += 2 if n != 1: lis[n] += 1 N = int(eval(input())) lis =...
def prime_factorize(N,lis): a = [] n = N while n % 2 == 0: lis[2] += 1 n //= 2 f = 3 while f * f <= N: if n % f == 0: lis[f] += 1 n //= f else: f += 2 if n != 1: lis[n] += 1 N = int(eval(input())) lis =...
p03213
import itertools from collections import Counter n = int(eval(input())) # 素因数分解した結果のリスト # {1: [], 2: [2], 3: [3], 4: [2, 2], 5: [5]} divs = {} primes = [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] for i in range(1, n + 1): divs[i] = [] x = i ...
import itertools import math import os import sys if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(10 ** 9) INF = float("inf") IINF = 10 ** 18 MOD = 10 ** 9 + 7 # MOD = 998244353 def get_factors(n): """ 素因数分解 :param int n: :rtype: list of int ...
p03213
from collections import Counter, defaultdict N = int(eval(input())) # 素数のリスト def createPrimeList(N, isTable=True): isPrime = [True] * N isPrime[0] = False isPrime[1] = False for i in range(2, N): if not isPrime[i]: continue for p in range(i * 2, N, i): ...
from collections import Counter, defaultdict N = int(eval(input())) def primeFactorization(N): primes = Counter() R = int(N**(0.5)) + 1 for num in range(2, R): while N % num == 0: N //= num primes[num] += 1 if N > 1 : primes[N] = 1 return primes...
p03213
from collections import Counter, defaultdict N = int(eval(input())) def primeFactorization(N): primes = Counter() R = int(N**(0.5)) + 1 for num in range(2, R): while N % num == 0: N //= num primes[num] += 1 if N > 1 : primes[N] = 1 return primes...
from collections import Counter, defaultdict N = int(eval(input())) # 素数のリスト def createPrimeList(N, isTable=True): isPrime = [True] * (N + 1) isPrime[0] = False isPrime[1] = False for i in range(2, N): if not isPrime[i]: continue for p in range(i * 2, N, i): ...
p03213
N = int(eval(input())) from math import ceil, sqrt, factorial from itertools import permutations def eratosthenes(n): l = [1 for i in range(n+1)] l[0] = l[1] = 0 for i in range(2, ceil(sqrt(n))): if l[i] == 0: continue for j in range(i*2, n+1, i): l[j] = 0 return l ...
N = int(eval(input())) p = [0] * (N+1) def is_prime(n): for i in range(2, n): if not n % i: return False return True def n(m): return sum([True for i in p if i >= m]) l = [i for i in range(2, N+1) if is_prime(i)] for i in range(2, N+1): for j in l: whi...
p03213
from collections import defaultdict, deque, Counter from heapq import heappush, heappop, heapify import math import bisect import random from itertools import permutations, accumulate, combinations import sys import string from bisect import bisect_left, bisect_right from math import factorial, ceil, floor ...
from collections import defaultdict, deque, Counter from heapq import heappush, heappop, heapify import math import bisect import random from itertools import permutations, accumulate, combinations, product import sys import string from bisect import bisect_left, bisect_right from math import factorial, ceil, ...
p03213
import math dic = {} N = int(eval(input())) for i in range(2, N+1): fact = [] while i % 2 == 0: fact.append(2) i //= 2 f = 3 while f*f <= i: if i%f == 0: fact.append(f) i //= f else: f += 2 if i != 1: fact.ap...
N = int(eval(input())) e = [0]*(N+1) for i in range(2, N+1): cur = i for j in range(2, i+1): while cur % j == 0: e[j] += 1 cur //= j def num(m): return len(list([x for x in e if x >= m-1])) print((num(75) + num(25)*(num(3)-1) + num(15)*(num(5)-1) + num(5)*(num(5)-...
p03213
from copy import deepcopy def mk_array(init_val, *args): args = args[::-1] res = [init_val for _ in range(args[0])] for arg in args[1:]: res = [deepcopy(res) for _ in range(arg)] return res N = int(eval(input())) e = [0 for _ in range(N + 1)] for i in range(2, N + 1): for...
N = int(eval(input())) e = [0 for _ in range(N + 1)] for i in range(2, N + 1): for j in range(2, i + 1): while i % j == 0: e[j] += 1 i //= j def num(m): return len(tuple([x for x in e if x >= m - 1])) ans = 0 ans += num(75) ans += num(25) * (num(3) - 1) ans ...
p03213
from collections import defaultdict def cand_count(v, d): return len(tuple([x for x in list(d.values()) if x >= v])) n = int(eval(input())) d = defaultdict(int) for i in range(2, n + 1): b = i j = 2 while j * j <= i: while b % j == 0: b //= j d[j] += ...
def num(v): return len(tuple([x for x in e if x >= v - 1])) n = int(eval(input())) e = [0] * (n + 1) for i in range(2, n + 1): b = i j = 2 while j * j <= i: while b % j == 0: b //= j e[j] += 1 j += 1 if b > 1: e[b] += 1 e = tuple([x...
p03213
from collections import defaultdict def get_yakusuu(num): yakusuu_dic = defaultdict(int) seed_primes = [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] for now_num in range(1, num + 1): for num_ele in seed_primes: if now_num < num...
def main2(): dic = {1:0, 2:0, 3:0, 4:0, 5:0, 6:0, 7:0, 8:0, 9:0, 10:1, 11:1, 12:1, 13:1, 14:2, 15:2, 16:3, 17:3, 18:3, 19:3, 20:8, 21:8, 22:11, 23:11, 24:11, 25:11, 26:14, 27:14, 28:32, 29:32, 30:35, 31:35, 32:35, 33:35, 34:42, 35:42, 36:42, 37:42, 38:49, 39:49, 40:49, 41:49, 42:49, 43:49, 44:75, 45:75, 46:86, 47:...
p03213
# -*- coding: utf-8 -*- """ 解説参考 ・まず素因数分解で階乗全部バラす ・そこからいい感じの組み合わせを探して数える """ N = int(eval(input())) # 階乗の素因数分解:ひとつずつ分解したものを合算 e = [0] * (N+1) # 階乗の各値ループ for i in range(2, N+1): num = i # 素因数分解するループ for j in range(2, N+1): while num % j == 0: num //= j e[...
# -*- coding: utf-8 -*- import sys from collections import Counter def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range...
p03213
N = int(eval(input())) lim = 1 for i in range(N): lim *= (i+1) Prime = [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] Ans = 0 for i in range(23): for j in range(i+1, 24): for k in range(j+1, 25): a, b, c = Prime[i], Prime[j], Prim...
import sys from collections import defaultdict def solve(): input = sys.stdin.readline N = int(eval(input())) primes = defaultdict(int) ans = 0 for i in range(1, N + 1): k = i for j in range(2, i+1): if j ** 2 > i: break if k % j == 0: ...
p03213
P = [1 for _ in range(100)] P[0]=0 P[1]=0 for i in range(2,10): for j in range(i*i,100,i): P[j] = 0 Q = [] for i in range(100): if P[i]==1: Q.append(i) C = {i:0 for i in Q} N = int(eval(input())) for i in range(2,N+1): x = i for p in C: while x%p==0: x...
P = [1 for _ in range(100)] P[0]=0 P[1]=0 for i in range(2,11): for j in range(i*i,100,i): P[j] = 0 Q = [] for i in range(100): if P[i]==1: Q.append(i) N = int(eval(input())) C = {p:0 for p in Q} for p in Q: cnt = 0 k = 1 while p**k<=N: for i in range(2,N+1): ...
p03213
P = [1 for _ in range(100)] P[0]=0 P[1]=0 for i in range(2,11): for j in range(i*i,100,i): P[j] = 0 Q = [] for i in range(2,100): if P[i]==1: Q.append(i) C = {q:0 for q in Q} N = int(eval(input())) for i in range(2,N+1): x = i for q in Q: while x%q==0: ...
P = [1 for _ in range(100)] P[0]=0 P[1]=0 for i in range(2,11): for j in range(i**2,100,i): P[j] = 0 Q = [] for i in range(100): if P[i]==1: Q.append(i) N = int(eval(input())) C = {p:0 for p in Q} for i in range(2,N+1): for p in Q: if i%p==0: x = i ...
p03213
from collections import Counter as c from itertools import permutations as p def fact(n): d=[] for i in range(2,int(n**0.5)+2): while n%i==0: n//=i d.append(i) if n!=1:d.append(n) return c(d) n=int(eval(input())) d=c() for i in range(1,n+1): d+=fact(i...
from collections import defaultdict as dd from itertools import permutations as p def factorize(n): d = dd(int) for i in range(2, int(n**0.5)+1): while n%i==0: d[i] += 1 n //= i if not n: break if n>1: d[n] += 1 return d N = in...
p03213
from collections import defaultdict as dd from itertools import permutations as p def factorize(n): d = dd(int) for i in range(2, int(n**0.5)+1): while n%i==0: d[i] += 1 n //= i if not n: break if n>1: d[n] += 1 return d N = in...
from collections import defaultdict as dd from itertools import permutations as p def factorize(n): d = dd(int) for i in range(2, int(n**0.5)+1): while n%i==0: d[i] += 1 n //= i if not n: break if n>1: d[n] += 1 return d N = in...
p03213
N = int(eval(input())) prime_number = [2, 3, 5, 7] prim = [2, 3, 5, 7] #素数作成 for i in range(2, 101): prime_flag = True for j in prim: if i % j == 0: prime_flag = False break if prime_flag: prime_number.append(i) prime_factor = [0] * len(prime_number) for i in range(2, N + 1): tmp...
ans = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 3, 3, 3, 3, 8, 8, 11, 11, 11, 11, 14, 14, 32, 32, 35, 35, 35, 35, 42, 42, 42, 42, 49, 49, 49, 49, 49, 49, 75, 75, 86, 86, 86, 86, 86, 86, 123, 123, 131, 131, 131, 131, 148, 148, 153, 153, 170, 170, 170, 170, 170, 170, 227, 227, 227, 227, 227, 227, 250, 250, 323, 32...
p03213
# M = a ** x * b ** y * c ** z # の約数の個数は(x + 1)*(y + 1)*(z + 1) # なので約数が75個になるには、以下パターンが考えられる # 75 # 25 * 3 # 15 * 5 # 5 * 5 * 3 # よって1~Nまで素因数分解して、各素因数の指数部分の値を求めて # 計算する import itertools def main(): N = int(eval(input())) d = [0] * (N+1) for i in range(2,N+1): cur = i fo...
from collections import defaultdict def main(): # 75 * 1 # 25 * 3 # 15 * 5 # 5 * 5 * 3 N = int(eval(input())) d = defaultdict(int) for n in range(1, N+1): for i in range(2, int(n ** 0.5) + 1): while n % i == 0: d[i] += 1 n = n...
p03213
from collections import defaultdict def main(): # 75 * 1 # 25 * 3 # 15 * 5 # 5 * 5 * 3 N = int(eval(input())) d = defaultdict(int) for n in range(1, N+1): for i in range(2, int(n ** 0.5) + 1): while n % i == 0: d[i] += 1 n = n...
from collections import defaultdict def prime_factor(n): ass = [] for i in range(2,int(n**0.5)+1): while n % i==0: ass.append(i) n = n//i if n != 1: ass.append(n) return ass def main(): N = int(eval(input())) d = defaultdict(int) for i...
p03213
N = 101 prime = [True]*(N+1) count = [0]*(N+1) prime[0] = prime[1] = False for i in range(N+1): if prime[i]: for j in range(2*i, N+1, i): prime[j] = False a = int(eval(input())) for i in range(1,a+1): cur = i for j in range(2,i+1): if prime[j]: while c...
N = int(eval(input())) e = [0] * (N+1) for i in range(2, N+1): cur = i for j in range(2, i+1): while cur % j == 0: e[j] += 1 cur //= j def num(m): # e の要素のうち m-1 以上のものの個数 return len(list([x for x in e if x >= m-1])) print((num(75) + num(25) * (num(3) - 1) + num(15...
p03213
n = int(eval(input())) def primes(m) : ps = [2] for i in range(3, m) : for p in ps : if i%p == 0 : break else : ps.append(i) return ps def fdivisor(m) : ps = primes(m) df = {p:0 for p in ps} for i in range(1, m+1) : ...
n = int(eval(input())) def primes(m) : ps = [2] for i in range(3, m+1) : for p in ps : if i%p == 0 : break else : ps.append(i) return ps def fdivisor(m) : ps = primes(m) df = {p:0 for p in ps} for i in range(1, m+1) : ...
p03213
from operator import mul from functools import reduce nCr = {} def cmb(n, r): if r == 0 or r == n: return 1 if r == 1: return n if (n,r) in nCr: return nCr[(n,r)] nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1) return nCr[(n,r)] a = int(eval(input())) b = [0 for i in range(15)] j = 0 c = ...
def cmb(n, r): if n - r < r: r = n - r if n <= 0: return 0 if r == 0: return 1 if r == 1: return n numerator = [n - r + k + 1 for k in range(r)] denominator = [k + 1 for k in range(r)] for p in range(2,r+1): pivot = denominator[p - 1] if pivot > 1: o...
p03213
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==[...
# 約数の数 = 素因数分解して、各素因数の(指数 + 1)をかけ合わせたもの # 例:12 = 2^2 * 3^1 -> 3 * 2 = 6 (1,2,3,4,6,12) # これが75になるためには、以下のペアを作れる必要がある。この組み合わせを数える # 75 : 指数が74 # 3 * 25 : 指数が2 , 24 # 5 * 15 : 指数が4 , 14 # 3 * 5 * 5 : 指数が2,4,4 import sys readline = sys.stdin.readline N = int(readline()) def factorization(n): res = [] ...
p03213
n = int(eval(input())) e = [0] * (n+1) for i in range(2, n+1): for j in range(2, i+1): while i % j == 0: e[j] += 1 i //= j def count(m): return len(list([x for x in e if x >= m-1])) a = count(75) b = count(25) * (count(3) - 1) c = count(15) * (count(5...
n = int(eval(input())) def nprf(m): pf = {} for i in range(2, m + 1): for j in range(2, i + 1): while i % j == 0: pf[j] = pf.get(j, 0) + 1 i //= j return pf def c(P, m): count = 0 for i in P: if P[i] >= m - 1: c...
p03213
# 因数を昇順に全列挙 from collections import Counter import math def com(n,r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) fac_list = [] def factoring(n): for i in range(2,n+1): if n % i == 0: fac_list.append(i) n = n // i break if n =...
def factoring(n): for i in range(2, n+1): while n % i == 0: n //= i d[i] += 1 N = int(eval(input())) d = [0]*(N+1) for n in range(2,N+1): factoring(n) def num(n): return len([e for e in d if e >= n]) ans = num(74) + num(14)*(num(4)-1) + num(24)*(num(2)-1)...
p03213
d={"o":1,"x":-1} N=int(input()) s=input() s+=s[0] def ans(a): for i in range(1,N+1): a=a+[a[i]*a[i-1]*d[s[i]]] if a[:2]==a[-2:]: return a[:-2] else: return [] for ini in [[1,1],[1,-1],[-1,1],[-1,-1]]: a=ans(ini) if a: print("".join(['S' if x>0 else 'W' f...
d={"o":1,"x":-1} w={"S":1,"W":-1} n={1:"S",-1:"W"} N=int(input()) s=input() s+=s[0] def ans(a): for i in range(1,N+1): a+=n[w[a[i]]*w[a[i-1]]*d[s[i]]] if a[:2]==a[-2:]: return a[:-2] else: return [] for ini in ["SS","SW","WS","WW"]: a=ans(ini) if a: pr...
p03798
a, b = list(map(str, input().split())) c = int(a + b) for i in range(c): if i**2 == c: ans = 'Yes' break else: ans = 'No' print(ans)
a, b = list(map(str, input().split())) c = int(a + b) for i in range(4, 317): if i**2 == c: ans = 'Yes' break else: ans = 'No' print(ans)
p03456
# coding: utf-8 import sys input = sys.stdin.readline N = int(input().replace(" ", "")) print(("Yes" if N**0.5 == int(N**0.5) else "No"))
# coding: utf-8 import sys input = sys.stdin.readline N = int(input().replace(" ", "")) print(("Yes" if (N**0.5).is_integer() else "No"))
p03456
import sys import math A,B=input().split() X=int(A+B) print(('Yes' if math.sqrt(X).is_integer() else 'No'))
import sys A,B=input().split() X=int(A+B) L=[x*x for x in range(1,1001)] if X in L: print('Yes') else: print('No')
p03456