input stringlengths 20 127k | target stringlengths 20 119k | problem_id stringlengths 6 6 |
|---|---|---|
from collections import Counter
def cmb(n, r, mod):
if ( r<0 or r>n ):
return 0
r = min(r, n-r)
return g1[n] * g2[r] * g2[n-r] % mod
mod = 10**9+7 #出力の制限
N = 10**5+1000
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
for i in range( 2, N + 1 ):
g1.append( ... | from collections import Counter
def cmb(n, r, mod):
if ( r<0 or r>n ):
return 0
r = min(r, n-r)
return g1[n] * g2[r] * g2[n-r] % mod
mod = 10**9+7 #出力の制限
N = 10**5+1000
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
for i in range( 2, N + 1 ):
g1.append( ... | p03253 |
from math import sqrt, ceil, factorial
from collections import defaultdict
def prime_factors(n):
i = 2
factors = defaultdict(int)
while i * i <= n:
if n % i:
i += 1
else:
n //= i
factors[i] += 1
if n > 1:
factors[n] += 1
re... | from collections import defaultdict
def prime_factorize(num):
prime_numbers = defaultdict(int)
i = 2
while i * i <= num:
if num % i == 0:
while num % i == 0:
prime_numbers[i] += 1
num //= i
i += 1
if num != 1:
prime_numbe... | p03253 |
import sys
N, M = list(map(int, input().split()))
factor = {}
tmp = 2
while(M // tmp >= 1):
if(M % tmp != 0):
if(tmp == 2):
tmp += 1
else:
tmp += 2
continue
M = M // tmp
factor[tmp] = factor.get(tmp, 0) + 1
if(factor == {}):
print((1)... | import sys
N, M = list(map(int, input().split()))
factor = {}
tmp = 2
while(M // tmp >= 1):
if(M % tmp != 0):
if(tmp == 2):
tmp += 1
elif(M // tmp < tmp):
tmp = M
else:
tmp += 2
continue
M = M // tmp
factor[tmp] = factor... | p03253 |
M = 10 ** 9 + 7
def main():
n, m = [int(s) for s in input().split()]
print((solve(m, n)))
def solve(m, n):
fs = list(factors(m))
table = dict()
table[1] = dict()
for f in fs:
table[1][f] = 1
h = 1
for _ in range(1, n.bit_length()):
row = dict()
... | import sys
MOD = 10 ** 9 + 7
def main():
n, m = [int(s) for s in input().split()]
print((solve(m, n)))
def solve(m, n):
factors = list(get_prime_factors(m))
h = max((c for f, c in factors), default=0)
table = dict()
table[1] = [1 for _ in range(h + 1)]
i = 1
while i ... | p03253 |
import sys
MOD = 10 ** 9 + 7
def main():
n, m = [int(s) for s in input().split()]
print((solve(m, n)))
def solve(m, n):
factors = list(get_prime_factors(m))
h = max((c for f, c in factors), default=0)
table = dict()
table[1] = [1 for _ in range(h + 1)]
i = 1
while i ... | M = 10 ** 9 + 7
def main():
n, m = [int(s) for s in input().split()]
print((solve(m, n, 10 ** 9 + 7)))
def solve(m, n, mod):
r = 1
for _, c in get_prime_factors(m):
r = r * mod_comb(c + n - 1, c, mod) % mod
return r
def mod_comb(n, k, m):
r = 1
for i in range(1, ... | p03253 |
import math
def nCr(n,r):
return (math.factorial(n)) // (math.factorial(r)) // (math.factorial(n-r))
def nHr(n,r):
return nCr(n+r-1, r-1)
def prime(n): # nまでの素数を列挙
import math
num_list = [i + 1 for i in range(2,n,2)]
list_prime = [2]
limit = math.sqrt(n)
if n == 2:
return ... | import math
def fact(a,b):
ans = 1
while a != b:
ans *= a
a -= 1
return ans
def nCr(n,r):
return (fact(n,r)) // (math.factorial(n-r))
def nHr(n,r):
return nCr(n+r-1, r-1)
def prime(n): # nまでの素数を列挙
import math
num_list = [i + 1 for i in range(2,n,2)]
list_pri... | p03253 |
#素因数分解
def soinsu_bunkai(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
# 組み合わせの総数 p=10**9+7 で割ったあまりを求める Satoooh Blog 2020/02/27 4分
"""n<10**7 , p は素数"""
def cmb(n, r, p):
if (r ... | #素因数分解
def soinsu_bunkai(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
# 組み合わせの総数 p=10**9+7 で割ったあまりを求める Satoooh Blog 2020/02/27 4分
"""n<10**7 , p は素数"""
def cmb(n, r, p):
if (r ... | p03253 |
from collections import Counter
mod = 1000000007
# nの素因数分解
def prime(n):
d = Counter()
i = 2
while n != 1:
while n%i == 0:
n //= i
d[i] += 1
i += 1
return d
# xのn乗を計算する
def mod_pow(x, n):
if n == 0:
return 1
elif n % 2 == 0:... | from collections import Counter
mod = 1000000007
# nの素因数分解
def prime(n):
d = Counter()
i = 2
while i*i <= n:
while n%i == 0:
n //= i
d[i] += 1
i += 1
if n > 1:
d[n] += 1
return d
# xのn乗を計算する
def mod_pow(x, n):
if n == 0:
... | p03253 |
from collections import Counter
mod = 1000000007
# nの素因数分解
def prime(n):
d = Counter()
i = 2
while i*i <= n:
while n%i == 0:
n //= i
d[i] += 1
i += 1
if n > 1:
d[n] += 1
return d
# xのn乗を計算する
def mod_pow(x, n):
if n == 0:
... | from collections import Counter
mod = 1000000007
# nの素因数分解
def factor(n):
d = Counter()
i = 2
while i*i <= n:
while n%i == 0:
n //= i
d[i] += 1
i += 1
if n > 1:
d[n] += 1
return d
# xのn乗を計算する
def mod_pow(x, n):
if n == 0:
... | p03253 |
import math
mod = 10**9 + 7
n, m = list(map(int, input().split()))
#mの素因数分解
#(prime, power)を要素としてもつ配列を返す関数を作る
def factorize(n):
fct = []
b, e = 2, 0
while b*b <= n:
while n%b == 0:
n //= b
e += 1
if e > 0:
fct.append((b, e))
b += 1
... | import math
mod = 10**9 + 7
n, m = list(map(int, input().split()))
#mの素因数分解
#(prime, power)を要素としてもつ配列を返す関数を作る
def factorize(n):
fct = []
b, e = 2, 0
while b*b <= n:
while n%b == 0:
n //= b
e += 1
if e > 0:
fct.append((b, e))
b += 1
... | p03253 |
import math
def div(m):
d = {}
temp = int(math.sqrt(m))+1
for i in range(2, temp):
while m%i== 0:
m //= i
if i in d:
d[i] += 1
else:
d[i] = 1
if d == {}:
d[m] = 1
else:
if m in d:
d[m] += 1
elif m != 1:
d[m] =1
return d
n,... | import math
def div(m):
d = {}
temp = int(math.sqrt(m))+1
for i in range(2, temp):
while m%i== 0:
m //= i
if i in d:
d[i] += 1
else:
d[i] = 1
if d == {}:
d[m] = 1
else:
if m in d:
d[m] += 1
elif m != 1:
d[m] =1
return d
n,... | p03253 |
#!/usr/bin/env python3
#ABC110 D
import math
from collections import Counter
N,M = list(map(int,input().split()))
mod = 10**9 + 7
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:
... | #!/usr/bin/env python3
#ABC110 D
import math
from collections import Counter
N,M = list(map(int,input().split()))
mod = 10**9 + 7
def factorize(n):
b = 2
fct = []
while b**2 <= n:
while n % b == 0:
n //= b
fct.append(b)
b += 1
if n > 1:
... | p03253 |
import math
N,M=list(map(int,input().split()))
dic={}
for i in range(2,int(M**0.5)+1):
if M%i==0:
dic.setdefault(i,1)
M//=i
while M%i==0:
dic[i]+=1
M//=i
if M==1: break
if M!=1: dic[M]=1
ans=1
for k in list(dic.keys()):
x=(dic[k]+N-1)
... | import math
N,M=list(map(int,input().split()))
dic={}
for i in range(2,int(M**0.5)+1):
if M%i==0:
dic.setdefault(i,1)
M//=i
while M%i==0:
dic[i]+=1
M//=i
if M==1: break
if M!=1: dic[M]=1
ans=1
for k in list(dic.keys()):
x=dic[k]
tmp=... | p03253 |
# -*- coding: utf-8 -*-
import math
def combinations_count(n, r):
return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
from collections import Counter
N, M = list(map(int, input().split()))
D = 1000000000 + 7
def primes(n):
primfac = []
d = 2
while d*d <= n:
w... | # -*- coding: utf-8 -*-
import math
# 高速 組み合わせ
def C(n, r):
a = 1
b = 1
for i in range(r):
a = a*(n-i)
b = b*(r-i)
return((a//b))
from collections import Counter
N, M = list(map(int, input().split()))
D = 1000000000 + 7
def primes(n):
primfac = []
d = 2
while d*d <= n... | p03253 |
from collections import Counter
from math import factorial
Q = 10**9+7
def primes(n):
primfac = [0]
d = 2
while d*d <= n:
while n%d == 0:
primfac[-1] += 1
n //= d
d += 1
if primfac[-1] != 0:
primfac.append(0)
if n > 1:
if ... | from math import factorial
Q = 10**9+7
def primes(n):
primfac = [0]
d = 2
while d*d <= n:
while n%d == 0:
primfac[-1] += 1
n //= d
d += 1
if primfac[-1] != 0:
primfac.append(0)
if n > 1:
if primfac[-1] == 0:
pr... | p03253 |
import math
MOD=10**9+7
def powmod(a,p):
if p==0:
return 1
elif p==1:
return a
else:
pow2=powmod(a,p//2)
if p%2==0:
return (pow2**2)%MOD
else:
return (a*pow2**2)%MOD
def invmod(a):
return powmod(a,MOD-2)
def comb_mod(n,r):
nPr=1
fact_r=1
for i in ran... | import math
MOD=10**9+7
def comb(n,r):
nPr=1
fact_r=1
for i in range(r):
nPr*=n-i
fact_r*=r-i
return nPr//fact_r
N,M=list(map(int,input().split()))
fact={}
for i in range(2,int(math.sqrt(M))+1):
if M==1:
break
while(M%i==0):
M//=i
if not i in fact:
fact[i]=1
... | p03253 |
#!/usr/bin/env python3
import sys
from math import *
from itertools import *
from collections import *
from functools import *
from operator import *
try:
from math import gcd
except Exception:
from fractions import gcd
MOD = 1000000007 # type: int
def prime_table(n):
rn = int(ceil(sqrt(... | #!/usr/bin/env python3
import sys
from math import *
from itertools import *
from collections import *
from functools import *
from operator import *
try:
from math import gcd
except Exception:
from fractions import gcd
MOD = 1000000007 # type: int
def prime_table(n):
t = [True] * (n + 1... | p03253 |
import math
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 = input().split()
a = [int(i) for i in a]
num = dict()
for i in prime_factors(a[1]):
if i not in num:
num... | import math
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
def egcd(a, b):
if a == 0:
return (b, 0, 1)
else:
g, y, x = egcd(b % a, a)
return (g, x - (b // a) * y,... | p03253 |
import math
import collections
N, M = input().strip().split(' ')
N, M = [int(N), int(M)]
#階乗
def combinations_count(n, r):
return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
#素因数分解
def prime_factors(n):
i = 2
factors = []
while i * i <= n:
if n % i:
... | N, M = [int(_) for _ in input().split()]
mod = 10 ** 9 + 7
MAX_N = 10 ** 5 + 100
#階乗
def calc_factorial(max_i):
factorial = [1] * max_i
for i in range(1, max_i):
factorial[i] = (i * factorial[i - 1]) % mod
return factorial
#素因数分解
def calc_factorization(n):
factorization = {}
... | p03253 |
from collections import Counter
from math import sqrt
#f_listとf_r_listの要素数は状況に応じて変えよう
MOD = (10 ** 9) + 7
list_size = 3 * (10 ** 5)
f_list = [1] * list_size
f_r_list = [1] * list_size
for i in range(list_size - 1):
f_list[i + 1] = int((f_list[i] * (i + 2)) % MOD)
def power(n, x):
if x == 1:
r... | from collections import Counter
from math import sqrt
#f_listとf_r_listの要素数は状況に応じて変えよう
MOD = (10 ** 9) + 7
list_size = 3 * (10 ** 5)
f_list = [1] * list_size
f_r_list = [1] * list_size
for i in range(list_size - 1):
f_list[i + 1] = int((f_list[i] * (i + 2)) % MOD)
def power(n, x):
if x == 1:
r... | p03253 |
# -*- coding: utf-8 -*-
'''Snippets for prime.
Available functions:
- is_included: Determine whether it is a prime number.
- generate: Generate a list of prime numbers using sieve of Eratosthenes.
'''
class Prime(object):
'''Represents a snippet for prime numbers.
'''
def __init__(self, n... | # -*- coding: utf-8 -*-
mod = 10 ** 9 + 7
'''Snippets for combination.
Available functions:
- count_combination: Count the total number of combinations.
'''
def count_combination(n: int, r: int, mod: int = 10 ** 9 + 7) -> int:
'''Count the total number of combinations.
nCr % mod.
... | p03253 |
from math import floor, sqrt
from collections import defaultdict
def factors(n):
d = defaultdict(int)
for i in range(2,floor(sqrt(n))+1):
while n % i == 0:
n //= i
d[i] += 1
if n == 1:
break
if n != 1:
d[n] += 1
return d
def inv(x,... | from math import floor, sqrt
from collections import defaultdict
N,M = list(map(int,input().split()))
d = defaultdict(int)
for i in range(2, floor(sqrt(M))+1):
while M % i == 0:
d[i] += 1
M //= i
if M != 1:
d[M] += 1
def comb(n,k):
if k == 0:
return 1
return comb(n-1... | p03253 |
# 素数リスト生成
def sieve(x):
if x < 2: return []
primes = [i for i in range(x)]
primes[1] = 0
for p in primes:
if p > x ** (1/2): break
if p == 0: continue
for np in range(2 * p, x, p): primes[np] = 0
return [p for p in primes if p != 0]
PS = sieve(10**7)
# 素因数分解
d... | # 素数リスト生成
def sieve(x):
if x < 2: return []
primes = [i for i in range(x)]
primes[1] = 0
for p in primes:
if p > x ** (1/2): break
if p == 0: continue
for np in range(2 * p, x, p): primes[np] = 0
return [p for p in primes if p != 0]
PS = sieve(10**6)
# 素因数分解
d... | p03253 |
import sys
MOD = 10 ** 9 + 7
def make_table(size=10**6, p=MOD):
fac = [None] * (size + 1)
fac[0] = 1
for i in range(size):
fac[i+1] = fac[i] * (i + 1) % p
ifac = [None] * (size + 1)
ifac[size] = pow(fac[size], p-2, p)
for i in range(size, 0, -1):
ifac[i-1] = ifac[i]... | import sys
MOD = 10 ** 9 + 7
def make_table(size=10**6, p=MOD):
fac = [None] * (size + 1)
fac[0] = 1
for i in range(size):
fac[i+1] = fac[i] * (i + 1) % p
ifac = [None] * (size + 1)
ifac[size] = pow(fac[size], p-2, p)
for i in range(size, 0, -1):
ifac[i-1] = ifac[i]... | p03253 |
import math
n, m=list(map(int, input().split()))
t = {}
a = int(math.sqrt(m))
s=0
line = [2, 3] + [i%2*2 + i//2 * 6 + 5 for i in range(a//3)]
while s==0:
for i in line:
cnt = 0
while m%i==0:
m=m//i
cnt += 1
if cnt>0:
t[i]=cnt
... | import math
n, m=list(map(int, input().split()))
t = {}
a = int(math.sqrt(m))
s=0
line = [2, 3] + [i%2*2 + i//2 * 6 + 5 for i in range(a)]
# line = [2] + list(range(3, m+2, 2))
for i in line:
# for i in range(2, m+2, 2):
# print(i)
cnt = 0
while m%i==0:
m=m//i
cnt += 1
... | p03253 |
import math
N, M = list(map(int, input().split()))
MOD = 10 ** 9 + 7
def factoring(k): #kを因数分解し、素因数とその個数を辞書に入れて返す。
dic = dict()
n = int(math.sqrt(k))+2
for i in range(2, n):
count = 0
while k%i == 0:
count += 1
k = k//i
if count != 0:
... | MOD = 10 ** 9 + 7
N, M = list(map(int, input().split()))
def factoring(k): #kを因数分解し、素因数とその個数を辞書に入れて返す。
import math
dic = dict()
n = int(math.sqrt(k))+2
for i in range(2, n):
count = 0
while k%i == 0:
count += 1
k = k//i
if count != 0:
... | p03253 |
import math
from collections import defaultdict
n, m = [int(i) for i in input().split()]
A = defaultdict(int)
p = 10 ** 9 + 7
if m == 1:
print((1))
exit()
def fact(n, p=10**9 + 7):
f = [1]
for i in range(1, n+1):
f.append(f[-1]*i%p)
return f
def invfact(n, f, p=10**9 +... | from math import sqrt
from collections import defaultdict
n, m = [int(i) for i in input().split()]
A = defaultdict(int)
p = 10 ** 9 + 7
def fact(n, p=10**9 + 7):
f = [1]
for i in range(1, n+1):
f.append(f[-1]*i%p)
return f
def invfact(n, f, p=10**9 + 7):
inv = [pow(f[n], p-2, ... | p03253 |
import math
n, m = list(map(int, input().split()))
mod = 10**9 + 7
b = []
c = int(math.sqrt(m))
for i in range(2, c+2):
count = 0
while m % i == 0:
count += 1
m = m // i
b.append(count)
if m > 1:
b.append(1)
fac = [1, 1]
inv = [1, 1]
finv = [1, 1]
for i in range(2... | import math
n, m = list(map(int, input().split()))
sqrt_m = math.sqrt(m)
sqrt_m = int(sqrt_m) + 1
mod = 10**9 + 7
fac = [1, 1]
inv = [1, 1]
finv = [1, 1]
for i in range(2, n + 31):
fac.append(fac[i-1] * i % mod)
inv.append(mod - inv[mod%i] * (mod//i) % mod)
finv.append(finv[i-1] * inv[i] % ... | p03253 |
import math
from collections import defaultdict
n, m = list(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)
... | import math
from collections import defaultdict
n, m = list(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)
... | p03253 |
# ABC110d
import sys
from collections import Counter
import math
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
n, m = list(map(int, input().split()))
MOD = 10**9+7
def prime_factorize(n):
a = []
while n % 2 == 0:
a.append(2)
n //= 2
f = 3
while f * f <= n:
... | # ABC110d
import sys
from collections import Counter
import math
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
n, m = list(map(int, input().split()))
MOD = 10**9+7
def prime_factorize(n):
a = []
while n % 2 == 0:
a.append(2)
n //= 2
f = 3
while f * f <= n:
... | p03253 |
N,M = list(map(int,input().split()))
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, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, ... | N,M = list(map(int,input().split()))
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, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, ... | p03253 |
from math import floor, sqrt
from collections import Counter
MOD = 10 ** 9 + 7
# xを素因数分解する
def getPrimeFactor(x):
ans = []
for d in range(2, floor(sqrt(x)) + 1):
while x % d == 0:
ans.append(d)
x //= d
if x != 1:
ans.append(x)
return ans
# x... | from math import floor, sqrt
from collections import Counter
MOD = 10 ** 9 + 7
# xを素因数分解する
def getPrimeFactor(x):
ans = []
for d in range(2, floor(sqrt(x)) + 1):
while x % d == 0:
ans.append(d)
x //= d
if x != 1:
ans.append(x)
return ans
def com... | p03253 |
def prime_facts(n: int) -> dict:
res = {}
if n % 2 == 0:
res[2] = 1
n //= 2
while n % 2 == 0:
res[2] += 1
n //= 2
if n % 3 == 0:
res[3] = 1
n //= 3
while n % 3 == 0:
res[3] += 1
n //= 3
k ... | from math import sqrt
def prime_facts(n: int) -> dict:
res = {}
d = 2
while d * d <= n:
if n % d == 0:
res[d] = 1
n //= d
while n % d == 0:
res[d] += 1
n //= d
if d == 2:
d += 1
else:... | p03253 |
from collections import defaultdict as dd
import sys
import math
n, m = list(map(int, input().split()))
dic = dd(int)
#M=1
if m == 1:
print((1))
sys.exit()
elif n == 1:
print((1))
sys.exit()
def combinations_count(n, r):
return math.factorial(n) // (math.factorial(n - r) * math.fact... | from collections import defaultdict as dd
from sys import exit
import math
n, m = list(map(int, input().split()))
dic = dd(int)
#M=1
if m == 1:
print((1))
exit()
def combinations_count(n, r):
return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
for i in range(2, math.ceil... | p03253 |
mod = 10**9+7
def hurui(n):
data = [i for i in range(2, n + 1)]
for d in data:
data = [x for x in data if (x == d or x % d != 0)]
return data
MAX = 10**5 + 100
fac = [1]*(MAX+1)
for i in range(1,MAX+1):
fac[i] = (fac[i-1]*i)%mod
rev_m = [1]*(MAX+1)
rev_m[MAX] = pow(fac[MAX],mod-2,mod)
... | from collections import defaultdict
import sys,heapq,bisect,math,itertools,string
def factors_nojit(n):
gaps = [1,2,2,4,2,4,2,4,6,2,6]
length, cycle = 11, 3
f, fs, nxt = 2, [], 0
while f * f <= n:
while n % f == 0:
fs.append(f)
n0 = n
n //= f
... | p03253 |
N,M=list(map(int,input().split()))
import math
a=[]
ans=1
def calc(n):#nの素因数分解
for i in range(2,int(n**0.5)+10):
count=0
while n%i==0:
n//=i
count+=1
if count>=1:
a.append([i,count])
if n!=1:
a.append([n,1])
def conb(n,k):
re... | N,M=list(map(int,input().split()))
a=[]
ans=1
def calc(n):#nの素因数分解
for i in range(2,int(n**0.5)+10):
count=0
while n%i==0:
n//=i
count+=1
if count>=1:
a.append([i,count])
if n!=1:
a.append([n,1])
calc(M)
def cmb(n, r):
if n -... | p03253 |
from collections import defaultdict
def prepare(n, MOD):
f = 1
factorials = [1] * (n + 1)
for m in range(1, n + 1):
f *= m
f %= MOD
factorials[m] = f
inv = pow(f, MOD - 2, MOD)
invs = [1] * (n + 1)
invs[n] = inv
for m in range(n, 1, -1):
inv *=... | from collections import defaultdict
def prepare(n, MOD):
f = 1
factorials = [1] * (n + 1)
for m in range(1, n + 1):
f *= m
f %= MOD
factorials[m] = f
inv = pow(f, MOD - 2, MOD)
invs = [1] * (n + 1)
invs[n] = inv
for m in range(n, 1, -1):
inv *=... | p03253 |
from collections import defaultdict
def prepare(n, MOD):
f = 1
factorials = [1] * (n + 1)
for m in range(1, n + 1):
f *= m
f %= MOD
factorials[m] = f
inv = pow(f, MOD - 2, MOD)
invs = [1] * (n + 1)
invs[n] = inv
for m in range(n, 1, -1):
inv *=... | from collections import defaultdict
def prepare(n, MOD):
f = 1
factorials = [1] * (n + 1)
for m in range(1, n + 1):
f *= m
f %= MOD
factorials[m] = f
inv = pow(f, MOD - 2, MOD)
invs = [1] * (n + 1)
invs[n] = inv
for m in range(n, 1, -1):
inv *=... | p03253 |
n,m=list(map(int,input().split()))
def c(n,m):
import math
if n-m<0:
return 0
return(math.factorial(n)//math.factorial(n-m)//math.factorial(m))
def factorize(n):
fct=[]
b,e=2,0
while b*b<=n:
while n%b==0:
n=n//b
e=e+1
if e>0:
... | n,m=list(map(int,input().split()))
def factorize(n):
fct=[]
b,e=2,0
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
l=factorize(m)
mod=10**9+7
ans... | p03253 |
def soin(num):
re = []
div = 2
while 1:
lim = int(num ** 0.5) + 1
while num % div:
div += 1
if div > lim:
re += [1]
return re
sisu = 0
while num % div == 0:
num //= div
sisu += 1
... | def soin(num):
re = []
div = 2
while 1:
lim = int(num ** 0.5) + 1
while num % div:
div += 1
if div > lim:
re += [1]
return re
sisu = 0
while num % div == 0:
num //= div
sisu += 1
... | p03253 |
import sys
readline = sys.stdin.buffer.readline
from collections import Counter
n,m = list(map(int,readline().split()))
mod = 10**9+7
"""素因数分解"""
def factrize(n):
b = 2
fct = []
while b*b <= n:
while n % b == 0:
n //= b
#もし素因数を重複させたくないならここを加えてfct.append(b)を消す
... | import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
"""
1*1*1*1*m = mなども含める
4をそのまま使う場合と2*2に分ける場合などの場合分けが必要
約数列挙からどうこうする?
"""
n,m = list(map(int,readline().split()))
mod = 10**9+7
def pow(n,p,mod=10**9+7): #繰り返し二乗法(nのp乗)
res = 1
while p > 0:
if p % 2 ==... | p03253 |
# https://atcoder.jp/contests/abc110/tasks/abc110_d
def get_prime_dic(n):
dic = {}
while n % 2 == 0:
if 2 in dic:
dic[2] += 1
else:
dic[2] = 1
n = n // 2
i = 3
while i <= n:
while n % i == 0:
n //= i
if i ... | N, M = [int(i) for i in input().split()]
mod = 10 ** 9 + 7
def func(M):
res = []
i = 2
while i * i <= M:
c=0
while M % i == 0:
M /= i
c += 1
if c > 0:
res.append(c)
i += 1
if M > 1:
res.append(1)
return res
def conb(n, r):
N, R = n, r
for i in rang... | p03253 |
from math import factorial as fact
import sys
input = sys.stdin.readline
N, M = list(map(int, input().split()))
num = []
p_flag = [True]*(int(M**0.5)+2)
for i in range(2, int(M**0.5)+2):
if p_flag:
for j in range(2*i, int(M**0.5)+2, i):
p_flag[j] = False
cnt = 0
... | from math import factorial as fact
from operator import mul
from functools import reduce
import sys
input = sys.stdin.readline
def cmb(n,r):
r = min(n-r,r)
if r == 0: return 1
over = reduce(mul, list(range(n, n - r, -1)))
under = reduce(mul, list(range(1,r + 1)))
return over // under
... | p03253 |
import math
from collections import Counter
from functools import reduce
from operator import mul
def get_factors(n):
"""
素因数分解
:param int n:
:type: list of int
"""
if n <= 1:
return []
ret = []
while n > 2 and n % 2 == 0:
ret.append(2)
n //= ... | import math
from collections import Counter
from functools import reduce
from operator import mul
def get_factors(n):
"""
素因数分解
:param int n:
:type: list of int
"""
if n <= 1:
return []
ret = []
while n > 2 and n % 2 == 0:
ret.append(2)
n //= ... | p03253 |
import math
import os
import sys
from collections import Counter
if os.getenv("LOCAL"):
sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
N, M = list(map(int, sys.stdin.readline().split()))
def get_factors(n):
"""
素... | import math
import os
import sys
from collections import Counter
from functools import reduce
from operator import mul
if os.getenv("LOCAL"):
sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
N, M = list(map(int, sys.stdin.rea... | p03253 |
from math import factorial as f
N, M = list(map(int, input().split()))
a1, a2 = 2, M
a = {}
while (a1 - 1) ** 2 <= a2 or a1 == a2:
if a2 % a1 == 0:
a2 //= a1
if a1 in a:
a[a1] += 1
else:
a[a1] = 1
else:
a1 += 1
p = 1
if a2 != 1:
a[a2] = ... | N, M = list(map(int, input().split()))
a1, a2 = 2, M
a = {}
while (a1 - 1) ** 2 <= a2 or a1 == a2:
if a2 % a1 == 0:
a2 //= a1
if a1 in a:
a[a1] += 1
else:
a[a1] = 1
else:
a1 += 1
p = 1
if a2 != 1:
a[a2] = 1
for v in list(a.values()):
... | p03253 |
import math
def prime_division(n):
ans = []
m = int(n ** 0.5)
i = 2
while i <= m:
if n % i == 0:
cnt = 0
while n % i == 0:
n //= i
cnt += 1
ans.append((i, cnt))
m = int(n ** 0.5)
i += 1
if... | import math
def prime_division(n):
ans = []
m = int(n ** 0.5)
i = 2
while i <= m:
if n % i == 0:
cnt = 0
while n % i == 0:
n //= i
cnt += 1
ans.append((i, cnt))
m = int(n ** 0.5)
i += 1
if... | p03253 |
def prime_factorize(num):
"""
This function performs prime factorization on the input natural number.
The result is returned in the form of a dictionary with the prime number as the key
and its number as the value.
:param num:
:return prime_factor: Dictionary with the prime number as the k... | def prime_factorize(num):
"""
This function performs prime factorization on the input natural number.
The result is returned in the form of a dictionary with the prime number as the key
and its number as the value.
:param num:
:return prime_factor: Dictionary with the prime number as the k... | p03253 |
def prime_factorize(num):
"""
This function performs prime factorization on the input natural number.
The result is returned in the form of a dictionary with the prime number as the key
and its number as the value.
:param num:
:return prime_factor: Dictionary with the prime number as the k... | def prime_factorize(num):
"""
This function performs prime factorization on the input natural number.
The result is returned in the form of a dictionary with the prime number as the key
and its number as the value.
:param num:
:return prime_factor: Dictionary with the prime number as the k... | p03253 |
N, M = list(map(int, input().split()))
MAX_NUM = 10 ** 9 + 7
def func(M):
res = []
i, c = 2, 0
while True:
if M % i == 0:
M = M / i
c+=1
else:
if c > 0:
res.append(c)
c = 0
i += 1
if M==1:
break
return res
def conb(n, r):
N, R =... | N, M = [int(i) for i in input().split()]
mod = 10 ** 9 + 7
def func(M):
res = []
i = 2
while i * i <= M:
c=0
while M % i == 0:
M /= i
c += 1
if c > 0:
res.append(c)
i += 1
if M > 1:
res.append(1)
return res
def conb(n, r):
N, R = n, r
for i in rang... | p03253 |
import math
def comb(x,y):
f = 1
for i in range(y):
f *= (x-i)
f //= (i+1)
return f
n,m = list(map(int,input().split()))
cnt = [0]
for i in range(2,m+1):
while m!=i:
if m%i==0:
m //=i
cnt[-1]+=1
else:
cnt.append(0)
... | import math
def comb(x,y):
f = 1
for i in range(y):
f *= (x-i)
f //= (i+1)
return f
n,m = list(map(int,input().split()))
i = 2
cnt = []
while i*i<=m:
c = 0
while m%i == 0:
m //= i
c += 1
if c>0:
cnt.append(c)
i+=1
if m>1:
c... | p03253 |
import collections
from functools import reduce
from operator import mul
def trial_division(n):
l = []
f = 2
while n > 1:
if n % f == 0:
l.append(f)
n /= f
else:
f += 1
return l
def combinations_count(n, r):
r = min(n - r, r)
... | import collections
from functools import reduce
from operator import mul
def trial_division(n):
l = []
f = 2
while f * f <= n:
if n % f == 0:
l.append(f)
n //= f
else:
f += 1
if n > 1:
l.append(n)
return l
def combina... | p03253 |
from math import sqrt
N, M = [int(_) for _ in input().split()]
p = []
m = M
max_x = 1
for i in range(2, int(sqrt(m)) + 1):
if m % i == 0:
cnt = 0
while m % i == 0:
cnt += 1
m //= i
p.append((i, cnt))
if cnt > max_x:
max_x = cnt
if... | def prime_factorization(n):
"""
nを素因数分解
:param n:
:return:素因数分解結果 [(素数S1, count S1),(素数S2, count S2), ...]
"""
from math import sqrt
if (n == 0): return []
if (n == 1): return [(1, 1)]
res = []
for i in range(2, int(sqrt(n)) + 1):
if n == 1: break
... | p03253 |
# -*- coding: utf-8 -*-
#############
# Libraries #
#############
import sys
input = sys.stdin.readline
import math
#from math import gcd
import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache
###... | # -*- coding: utf-8 -*-
#############
# Libraries #
#############
import sys
input = sys.stdin.readline
import math
#from math import gcd
import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache
###... | p03253 |
N_MAX = 10**6
MOD = 10**9 + 7
fac, finv, inv = [0]*N_MAX ,[0]*N_MAX, [0]*N_MAX
def com_init():
fac[0], fac[1] = 1, 1
finv[0], finv[1] = 1, 1
inv[1] = 1
for i in range(2, N_MAX):
fac[i] = fac[i - 1] * i % MOD
inv[i] = MOD - inv[MOD%i] * (MOD // i) % MOD
finv[i] = finv[i ... | N_MAX = 10**6
MOD = 10**9 + 7
fac, finv, inv = [0]*N_MAX ,[0]*N_MAX, [0]*N_MAX
def com_init():
fac[0], fac[1] = 1, 1
finv[0], finv[1] = 1, 1
inv[1] = 1
for i in range(2, N_MAX):
fac[i] = fac[i - 1] * i % MOD
inv[i] = MOD - inv[MOD%i] * (MOD // i) % MOD
finv[i] = finv[i ... | p03253 |
from math import factorial
from math import sqrt
def nCr(n,r):
return factorial(n)//(factorial(r)*factorial(n-r))
"""
def factorize(p):
b=[]
for i in range(2,int(sqrt(p)+2)):
a=0
while((p%i)==0):
a+=1
p=p//i
if a!=0:
b.ap... | from math import factorial
from math import sqrt
def nCr(n,r):
a=1
x=n
while(x!=n-r):
a*=x
x-=1
b=1
x=r
while(x!=0):
b*=x
x-=1
return a//b
INF=10**9+7
N,m=list(map(int,input().split()))
sum=1
yd = {}
i = 2
while m != 1:
while m % i == 0:
... | p03253 |
import math
n, m = list(map(int, input().split()))
mod = 10**9+7
def prime_decomposition(n):
p = 2
prime = {}
while n!=1:
while n%p == 0:
n = n//p
if p not in prime:
prime[p] = 0
prime[p] += 1
p += 1
return prime
pri... | n, m = list(map(int, input().split()))
mod = 10**9+7
def prime_decomposition(n):
p = 2
prime = {}
while n!=1:
while n%p == 0:
n = n//p
if p not in prime:
prime[p] = 0
prime[p] += 1
p += 1
return prime
primes = prime_dec... | p03253 |
from collections import Counter
import math
n,m = list(map(int, input().split()))
def combinations_count(n, r):
return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def prime_decomposition(n, table):
i = 2
while i * i <= n:
while n % i == 0:
n /= i
... | from collections import Counter
import math
n,m = list(map(int, input().split()))
def combinations_count(n, r):
l = 1
for num in range(1,r+1):
l *= (n+num)
l = l // num
return l
def prime_decomposition(n, table):
i = 2
while i * i <= n:
while n % i == 0:
... | p03253 |
N,M=list(map(int,input().split()))
mod=10**9+7
from math import factorial
from collections import Counter
def soinsuu(n):
list_=[]
while(n!=1):
for i in range(2,int(n**0.5)+1):
if n%i==0:
list_.append(i)
n=n//i
break
e... | N,M=list(map(int,input().split()))
from collections import Counter
def soinsuu(n):
list_=[]
while(n!=1):
for i in range(2,int(n**0.5)+1):
if n%i==0:
list_.append(i)
n=n//i
break
else:
list_.append(n)
... | p03253 |
from math import factorial as fac
from collections import defaultdict as ddict
n,m = list(map(int,input().split()))
d = ddict(int)
ans = 1
mod = 10**9+7
def cc(n,r):
return fac(n)//fac(r)//fac(n-r)
for i in range(2,int(m**.5)+1):
while m % i == 0:
d[i] += 1
m //= i
if m > 1:
d[m] += 1
for x ... | from math import factorial as fac
from collections import defaultdict as ddict
n,m = list(map(int,input().split()))
d = ddict(int)
ans = 1
mod = 10**9+7
def f2(n,r):
ret = 1
for i in range(n,n-r,-1):
ret *= i
return ret
def cc(n,r):
t = min(r,n-r)
return f2(n,t)//fac(t)
for i in range(2,int(... | p03253 |
from math import factorial
N, M = list(map(int,input().split()))
# 素因数分解(小さい方から順に割っていく。sqrt(2)まで)
def factorize(n):
i = 2
table = [0]
cnt= [0]
while i * i <= n:
while n % i == 0:
n /= i
if table[-1] != i:
table.append(i)
cnt.a... | from math import factorial
N, M = list(map(int,input().split()))
# 素因数分解(小さい方から順に割っていく。sqrt(2)まで)
def factorize(n):
i = 2
table = [0]
cnt= [0]
while i * i <= n:
while n % i == 0:
n /= i
if table[-1] != i:
table.append(i)
cnt.a... | p03253 |
from math import sqrt, floor
from collections import defaultdict
def comb(n,m):
if m == 0:
return 1
return comb(n-1,m-1)*n // m
def facts(n):
dic = defaultdict(int)
for i in range(2,floor(sqrt(n))+1):
while n % i == 0:
n //= i
dic[i] += 1
if n ... | from math import sqrt,floor
def comb(n,m):
if m == 0:
return 1
return comb(n-1,m-1)*n // m
n,m=list(map(int,input().split()))
mod=10**9+7
def factorization(x):
ans=[]
for i in range(2,floor(sqrt(x))+1):
if x%i==0:
cnt=0
while x%i==0:
x//=i
cnt+=1
ans.appe... | p03253 |
import math
def ncr(n,r):
return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))
def factorize(n):
d = {}
m = 2
while m*m <= n:
if n%m == 0:
d[m] = 0
while n%m == 0:
n //= m
d[m] += 1
m += 1
if n > 1:
d[n] =... | N,M = list(map(int,input().split()))
MOD = 10**9+7
from collections import Counter
c = Counter()
m = 2
while(m**2 <= M):
if M%m == 0:
while(M%m == 0):
c[m] += 1
M //= m
else:
m += 1
if M > 1 : c[M] += 1
MAXN = N+100
fac = [0 for _ in range(MAXN)]
inv = [0... | p03253 |
#http://nihaoshijie.hatenadiary.jp/entry/2018/02/03/115759
N,M=list(map(int,input().split()))
P=10**9+7
def egcd(a, b):
(x, lastx) = (0, 1)
(y, lasty) = (1, 0)
while b != 0:
q = a // b
(a, b) = (b, a % b)
(x, lastx) = (lastx - q * x, x)
(y, lasty) = (lasty - q * y, ... | import math
N,M=list(map(int,input().split()))
def primecheck(K):
A=int(math.sqrt(K))+1
for i in range(2,A+1):
if K%i==0:
return i
return 1
D=dict()
while(True):
X=int(math.sqrt(M))+1
for i in range(2,X+1):
if M%i==0:
while(True):
... | p03253 |
import math
N,M=list(map(int,input().split()))
def primecheck(K):
A=int(math.sqrt(K))+1
for i in range(2,A+1):
if K%i==0:
return i
return 1
D=dict()
while(True):
X=int(math.sqrt(M))+1
for i in range(2,X+1):
if M%i==0:
while(True):
... | import math
N,M=list(map(int,input().split()))
def primecheck(K):
A=int(math.sqrt(K))+1
for i in range(2,A+1):
if K%i==0:
return i
return 1
D=dict()
while(True):
X=int(math.sqrt(M))+1
for i in range(2,X+1):
if M%i==0:
while(True):
... | p03253 |
def comb(a, b):
b = min(b, a - b)
res = 1
for i in range(b):
res *= (a - i)
res %= MOD
for div in range(1, b + 1):
res = res * pow(div, MOD - 2, MOD) % MOD
return res
def prime_factorization(x):
res = []
i = 2
left = x + 0
while True:
... | MOD = 10 ** 9 + 7
def prime_factorization(n):
i = 2
res = []
while i * i <= n:
cnt = 0
while n % i == 0:
n /= i
cnt += 1
if cnt > 0:
res.append(cnt)
i += 1
if n > 1:
res.append(1)
return res
def comb(a... | p03253 |
class Calc:
def __init__(self, max_value, mod):
"""combination(max_value, all)"""
fact = [-1] * (max_value + 1)
fact[0] = 1
fact[1] = 1
for x in range(2, max_value + 1):
fact[x] = x * fact[x - 1] % mod
invs = [1] * (max_value + 1)
invs[m... | class Calc:
def __init__(self, max_value, mod):
"""combination(max_value, all)"""
fact = [-1] * (max_value + 1)
fact[0] = 1
fact[1] = 1
for x in range(2, max_value + 1):
fact[x] = x * fact[x - 1] % mod
invs = [1] * (max_value + 1)
invs[m... | p03253 |
class Calc:
def __init__(self, max_value, mod):
"""combination(max_value, all)"""
fact = [-1] * (max_value + 1)
fact[0] = 1
fact[1] = 1
for x in range(2, max_value + 1):
fact[x] = x * fact[x - 1] % mod
invs = [1] * (max_value + 1)
invs[m... | def gen(n):
x = n
d = 2
cnt = 0
while x % d == 0:
x //= d
cnt += 1
yield cnt
d = 3
while d * d <= n:
cnt = 0
while x % d == 0:
x //= d
cnt += 1
yield cnt
d += 2
if x > 1:
yield 1
def... | p03253 |
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline ####
def int1(x): return int(x) - 1
def II(): return int(eval(input()))
def MI(): return list(map(int, input().split()))
def MI1(): return list(map(int1, input().split()))
def LI(): return list(map(int, input().split()))
def LI1(): re... | import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline ####
def int1(x): return int(x) - 1
def II(): return int(eval(input()))
def MI(): return list(map(int, input().split()))
def MI1(): return list(map(int1, input().split()))
def LI(): return list(map(int, input().split()))
def LI1(): return... | p03253 |
class Solution:
def solve(self, N: int, M: int) -> int:
mod = 10**9+7
INT_MAX = 10**7
# calculate {m+n}C{n}
def egcd(a, b):
if a == 0:
return b, 0, 1
else:
g, y, x = egcd(b % a, a)
return g, x -... | import math
class Solution:
def solve(self, N: int, M: int) -> int:
mod = 10**9+7
INT_MAX = 10**9
# calculate {m+n}C{n}
def egcd(a, b):
if a == 0:
return b, 0, 1
else:
g, y, x = egcd(b % a, a)
... | p03253 |
import collections,math,sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N,M = LI()
ans = 1
def prime_factor(num):
prime_factor = collections.defaultdict(int)
for i in range(2,int(num**0.5)+1):
while num%i==0:
prime_factor[i] += 1
num //= i
... | import collections,sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N,M = LI()
ans = 1
def prime_factor(num):
prime_factor = collections.defaultdict(int)
for i in range(2,int(num**0.5)+1):
while num%i==0:
prime_factor[i] += 1
num //= i
if nu... | p03253 |
# -*- coding: utf-8 -*-
"""
参考:http://drken1215.hatenablog.com/entry/2018/09/23/224100
http://tutuz.hateblo.jp/entry/2018/09/24/121248
・素因数分解と重複組み合わせ
・毎回階乗やると死ぬから階乗と逆元のテーブル作る(忘れてた)
"""
from collections import defaultdict
from math import sqrt
MOD = 10 ** 9 + 7
def fact_prime(num):
d = defaultd... | # -*- coding: utf-8 -*-
import sys
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(c)] for j in range(b)] for i in ... | p03253 |
#How many ways M=a1*a2*...*aN ex)N=2,M=6 a={1,6},{2,3},{3,2},{6,1}
import math
n,m=list(map(int,input().split()))
factor=[]
c=0
mod=10**9+7
#Prime Factorization [number,times]
while m%2 == 0:
m//=2
c+=1
if c != 0:
factor.append([2,c])
#Alternate
for i in range(3,m+1,2):
c=0
while m%... | #How many ways M=a1*a2*...*aN ex)N=2,M=6 a={1,6},{2,3},{3,2},{6,1}
import math
n,m=list(map(int,input().split()))
factor=[]
c=0
mod=10**9+7
#Prime Factorization [number,times]
while m%2 == 0:
m//=2
c+=1
'''
if c>=20:
c=0
break
'''
if c != 0:
factor.append([2... | p03253 |
from math import factorial
from collections import Counter
N, M = list(map(int, input().split()))
MOD = 10 ** 9 + 7
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 /... | import sys
from collections import Counter
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N, M = lr()
MOD = 10 ** 9 + 7
def prime_factorize(n): # Nの素因数分解
a = []
while n % 2 == 0:
a.append(2)
n //= 2
f = 3
whi... | p03253 |
N, M = [int(i) for i in input().split()]
def prime_decomposition(n):
i = 2
table = []
while i * i <= n:
while n % i == 0:
n //= i
table.append(i)
i += 1
if n > 1:
table.append(n)
return table
def cmb(n, r):
N, R = n, r
for i in range(1, r):
N *= n - i... | N, M = [int(i) for i in input().split()]
def prime_decomposition(n):
table = []
i = 2
while i * i <= n:
count = 0
while n % i == 0:
n //= i
count += 1
if count != 0:
table.append((i, count))
i += 1
if n > 1:
table.append((n, 1))
return table
def cmb(n... | p03253 |
import math
import sys
import bisect
import itertools
N, M = [int(x) for x in input().split()]
MOD = 10 ** 9 + 7
divisor = []
dict = {}
m = M
d = 2
while m != 1:
while m % d == 0:
# divisor.append(d)
m //= d
dict[d] = dict.get(d, 0) + 1
d += 1
C = list(dict.values()... | import math
N, M = [int(x) for x in input().split()]
MOD = 10 ** 9 + 7
divisor = []
dict = {}
m = M
d = 2
while m != 1:
while m % d == 0:
# divisor.append(d)
m //= d
dict[d] = dict.get(d, 0) + 1
d += 1
C = list(dict.values())
ret = 1
# def combinations_count(n, r... | p03253 |
import math
N, M = [int(x) for x in input().split()]
MOD = 10 ** 9 + 7
divisor = []
dict = {}
m = M
d = 2
while m != 1:
while m % d == 0:
# divisor.append(d)
m //= d
dict[d] = dict.get(d, 0) + 1
d += 1
C = list(dict.values())
ret = 1
# def combinations_count(n, r... | import math
N, M = [int(x) for x in input().split()]
MOD = 10 ** 9 + 7
divisor = []
dict = {}
m = M
d = 2
while d*d <= m:
while m % d == 0:
m //= d
dict[d] = dict.get(d, 0) + 1
d += 1
if m > 1:
dict[d] = dict.get(m, 0) + 1
C = list(dict.values())
ret = 1
# def com... | p03253 |
import math
N, M = list(map(int, input().split()))
max = int(math.sqrt(M))
mod = 7 + 10**9
F = []
def Prime(i): #素数であればTrueを返す
root = math.sqrt(i)
j, div = 2, False
while j <= root:
if i % j == 0:
div = True
break
j += 1
return (True if not div el... | import math
def InvMod(i, pow, mod): #階乗のmodを計算
if pow == 1:
return i % mod
else:
if pow % 2 == 0:
return InvMod((i**2) % mod, pow//2, mod) % mod
else:
return InvMod((i**2) % mod, pow//2, mod) * i % mod
def Prime(i): #素数であればTrueを返す
root = math.sq... | p03253 |
from collections import Counter
import math
N,M = list(map(int,input().split()))
nf = math.factorial(N)
# 因数分解
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
... | from collections import Counter
import math
mod = 10**9+7
N,M = list(map(int,input().split()))
factors = []
f = 2
while M%f==0:
M//=2
factors.append(f)
f = 3
while f*f<=M:
if M%f==0:
M//=f
factors.append(f)
else:
f+=2
if M!=1:
factors.append(M)
count = Count... | p03253 |
from math import factorial
def H(x, y):
return factorial(x + y - 1) // (factorial(x - 1) * factorial(y))
n, m = list(map(int, input().split()))
p = 2
prime_factorization = []
while p * p <= m:
count = 0
while m % p == 0:
m //= p
count += 1
if count > 0:
prime_factoriz... | def C(x, y):
z = 1
for i in range(x, x-y, -1):
z *= i
for i in range(y, 1, -1):
z //= i
return z
def H(x, y):
return C(x+y-1, y)
n, m = list(map(int, input().split()))
p = 2
prime_factorization = []
while p * p <= m:
count = 0
while m % p == 0:
m //= p
... | p03253 |
# -*- coding: utf-8 -*-
from collections import defaultdict
# mod mでの二項係数を求める
class BiCoeff(object):
def __init__(self, MAX, m):
super(BiCoeff, self).__init__()
fac = [0]*MAX
finv = [0]*MAX
inv = [0]*MAX
fac[0] = 1
fac[1] = 1
finv[0] = 1
... | # -*- coding: utf-8 -*-
def primeFactors(n):
res = []
while n%2==0:
res.append(2)
n //= 2
x = 3
while n>1 and n>=x*x:
while n%x==0:
res.append(x)
n //= x
x += 2
if n>1:
res.append(n)
return res
class BiCoeff(object)... | p03253 |
import math
import collections
n, m = list(map(int, input().split()))
factor = []
tmp = int(m ** (1/2)) + 1
for i in range(2, tmp):
while m % i == 0:
m //= i
factor.append(i)
if m > 1:
factor.append(m)
num = list(collections.Counter(factor).most_common())
ans = 1
for x in num:
... | import collections
n, m = list(map(int, input().split()))
factor = []
tmp = int(m ** (1/2)) + 1
for i in range(2, tmp):
while m % i == 0:
m //= i
factor.append(i)
if m > 1:
factor.append(m)
num = list(collections.Counter(factor).most_common())
def comb(n, r):
tmp = 1
for... | p03253 |
import sys
stdin = sys.stdin
def li(): return list(map(int, stdin.readline().split()))
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return list(map(float, stdin.readline().split()))
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return... | import sys
stdin = sys.stdin
def li(): return list(map(int, stdin.readline().split()))
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return list(map(float, stdin.readline().split()))
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return... | p03253 |
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**5)
def li(): return list(map(int, stdin.readline().split()))
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return list(map(float, stdin.readline().split()))
def ls(): return stdin.readline().split()
def ns(): return stdin.readl... | import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
def li(): return list(map(int, stdin.readline().split()))
def li_(): return [int(x) - 1 for x in stdin.readline().split()]
def lf(): return list(map(float, stdin.readline().split()))
def ls(): return stdin.readline().split()
def ns(): return stdin.r... | p03253 |
import math
import sys
import collections
mod = 1000000007
sys.setrecursionlimit(mod)
fact = {1: 1}
def run(n, m):
# print('{}を{}個の数列で表現'.format(m, n))
ans = 1
primes = []
for i in range(2, m):
if m == 1:
break
if i*i > m:
break
if m... | import math
import sys
import collections
mod = 1000000007
sys.setrecursionlimit(mod)
fact = {1: 1}
def run(n, m):
# print('{}を{}個の数列で表現'.format(m, n))
ans = 1
primes = []
for i in range(2, m):
if m == 1:
break
if i*i > m:
break
if m... | p03253 |
import math
mod = 1000000007
N,M = list(map(int,input().strip().split()))
m_sqrt = int(math.sqrt(M))
def P(n, r):
return math.factorial(n)//math.factorial(n-r)
def C(n, r):
return P(n, r)//math.factorial(r)
ans = 1
cnt = 0
while M%2 == 0:
M = M//2
cnt += 1
ans *= C(N+cnt-1,cnt)
cnt = 0
for i... | import math
mod = 1000000007
N,M = list(map(int,input().strip().split()))
l = []
def P(n, r):
return math.factorial(n)//math.factorial(n-r)
def C(n, r):
return P(n, r)//math.factorial(r)
ans = 1
cnt = 0
while M%2 == 0:
M //= 2
cnt += 1
l.append(cnt)
cnt = 0
i = 3
while i**2 <= M:
cnt... | p03253 |
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
MOD = 10**9+7
fac = [1, 1] # 元テーブル
f_inv = [1, 1] # 逆元テーブル
inv = [0, 1] # 逆元テーブル計算用テーブル
def prepare(n, mod):
for i in range(2, n+1):
fac.append((fac[-1] * i) % mod)
inv.append((-in... | import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
MOD = 10**9+7
fac = [1, 1] # 元テーブル
f_inv = [1, 1] # 逆元テーブル
inv = [0, 1] # 逆元テーブル計算用テーブル
def prepare(n, mod):
for i in range(2, n+1):
fac.append((fac[-1] * i) % mod)
def cmb(n, r, mod):... | p03253 |
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
MOD = 10**9+7
fac = [1, 1] # 元テーブル
f_inv = [1, 1] # 逆元テーブル
inv = [0, 1] # 逆元テーブル計算用テーブル
def prepare(n, mod):
for i in range(2, n+1):
fac.append((fac[-1] * i) % mod)
def cmb(n, r, mod):... | # AC: msec(Python3)
from math import factorial
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
MOD = 10**9+7
def cmb(n, r):
if n < 0 or r < 0:
return 0
if r > n:
return 0
r = min(n-r, r)
res = 1
for i in range(r):
... | p03253 |
from math import factorial
def pff(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
def comb(n, r):
return factorial(n) // (factorial(n - r) * factorial(r))
N, M =... | from math import factorial
from operator import mul
from functools import reduce
def comb2(n,r):
r = min(n - r, r)
if r == 0: return 1
over = reduce(mul, list(range(n, n - r, -1)))
under = reduce(mul, list(range(1, r + 1)))
return over // under
def pff(m):
pf = {}
for i in ran... | p03253 |
import math
def main():
N,M = list(map(int,input().split()))
div_list = []
d = 2
ans = 1
while M != 1:
count = 0
while M%d == 0:
count += 1
M //= d
div_list.append(count)
d += 1
for i in div_list:
a = math.factorial(... | import sys
input = sys.stdin.buffer.readline
from collections import defaultdict
import copy
def main():
N,M = list(map(int,input().split()))
d = defaultdict(int)
MOD = 10**9+7
R = 10**5+100
fac = [0 for _ in range(R+1)]
fac[0],fac[1] = 1,1
inv = copy.deepcopy(fac)
invfac =... | p03253 |
import sys
input = sys.stdin.buffer.readline
from collections import defaultdict
import copy
def main():
N,M = list(map(int,input().split()))
d = defaultdict(int)
MOD = 10**9+7
R = 10**5+100
fac = [0 for _ in range(R+1)]
fac[0],fac[1] = 1,1
inv = copy.deepcopy(fac)
invfac =... | import sys
input = sys.stdin.buffer.readline
def main():
N,M = list(map(int,input().split()))
MOD = 10**9+7
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... | p03253 |
import sys
input = sys.stdin.buffer.readline
def main():
K,M = 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
i... | import sys
input = sys.stdin.buffer.readline
def main():
K,M = 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
i... | p03253 |
N, M = [ int(it) for it in input().split() ]
MOD = 1000000007
import math
sM = int(math.sqrt(M)+1)
p_li = []
m = M
for i in range(sM):
for j in range(2,sM+1):
if (m%j)==0:
p_li.append(j)
m//=j
break
if (m==1):
break
if (m!=1):
p_li.append(m)
import collect... | N, M = [ int(it) for it in input().split() ]
MOD = 1000000007
import math
sM = int(math.sqrt(M)+1)
p_li = []
m = M
for j in range(2,sM+1):
for i in range(sM):
if (m%j)==0:
p_li.append(j)
m//=j
else:
break
if (m==1):
break
if (m!=1):
p_li.append(m)
imp... | p03253 |
import sys
import math
def input():
return sys.stdin.readline()[:-1]
def combinations_count(n, r):
return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def trial_division(n):
factor = []
tmp = int(math.sqrt(n)) + 1
for num in range(2,tmp):
while n % num == 0:... | import sys
import math
def input():
return sys.stdin.readline()[:-1]
def combinations_count(n, r):
return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def trial_division(n):
factor = []
tmp = int(math.sqrt(n)) + 1
for num in range(2,tmp):
while n % num == 0:... | p03253 |
from collections import Counter
def factorization(n) -> list:
if n==1:
return [1]
ret = []
i = 2
while i*i<=n:
while n%i==0:
n //= i
ret.append(i)
i += 1
if n!=1:
ret.append(n)
return ret
n,m = list(map(int,input().split()))
mod = 10**9+7
if m==1:
print((1));exit()
factors = C... | from collections import Counter
def factorization(n) -> list:
if n==1:return [1]
ret = []
i = 2
while i*i<=n:
while n%i==0:
n //= i
ret.append(i)
i += 1
if n!=1:ret.append(n)
return ret
from operator import mul
from functools import reduce
def cmb(n,r):
if n < r:return 0
r = min(n-r... | p03253 |
#coding utf-8
import math
N,M=list(map(int,input().split()))
def soinsu(m):
fact =[]
i = 2
while i*i<=m:
if m%i==0:
fact.append(i)
m //=i
else:
i +=1
if m>1:
fact.append(m)
return fact
fact=soinsu(M)
counting=[]
for i in fact:
counting.append(fact.count(i)... | #coding utf-8
import math
from operator import mul
from functools import reduce
N,M=list(map(int,input().split()))
def soinsu(m):
fact =[]
i = 2
while i*i<=m:
if m%i==0:
fact.append(i)
m //=i
else:
i +=1
if m>1:
fact.append(m)
return fact
fact=soinsu(M)
coun... | p03253 |
N, M = list(map(int, input().split()))
import math
def prime_fac(n):
p_lis = []
temp = n
for i in range(2, int(math.sqrt(n)) + 1):
if temp % i == 0:
cnt = 0
while temp % i == 0:
cnt += 1
temp //= i
p_lis.append([i, cnt])
if temp != 1:
p_lis.append([te... | N, M = list(map(int, input().split()))
import math
def prime_fac(n):
p_lis = []
temp = n
for i in range(2, int(math.sqrt(n)) + 1):
if temp % i == 0:
cnt = 0
while temp % i == 0:
cnt += 1
temp //= i
p_lis.append([i, cnt])
if temp != 1:
p_lis.append([te... | p03253 |
import copy
N,M=list(map(int,input().split()))
mod=10**9+7
#x以下の素数の列挙
import math
x=math.floor(math.sqrt(10**9))
L=math.floor(math.sqrt(x))#平方根を求める
Primelist=[i for i in range(x+1)]
Primelist[1]=0#素数でないものは0にする.
for i in Primelist:
if i>L:
break
if i==0:
continue
for j in... | N,M=list(map(int,input().split()))
mod=10**9+7
import math
L=math.floor(math.sqrt(M))
X=dict()
for i in range(2,L+2):
while M%i==0:
X[i]=X.get(i,0)+1
M=M//i
if M!=1:
X[M]=X.get(M,0)+1
def Combi2(a,b):#aは大きいが、bは小さいとき
if b>a:
return 0
ANS=1
for... | p03253 |
import math
import collections
def trial_division_sqrt(n):
prime_count = collections.Counter()
for i in range(2, int(math.sqrt(n)) + 2):
while n % i == 0:
n /= i
prime_count[i] += 1
if n > 1:
prime_count[n] += 1
return prime_count
def pc(n, r):
... | import math
import collections
def trial_division_sqrt(n):
prime_count = collections.Counter()
for i in range(2, int(math.sqrt(n)) + 2):
while n % i == 0:
n /= i
prime_count[i] += 1
if n > 1:
prime_count[n] += 1
return prime_count
def pc(n, r):
... | p03253 |
import sys
input = sys.stdin.readline
from collections import *
def prime_fact(n):
prime = Counter()
m = 0
while not n % 2:
prime[2] += 1
n //= 2
m += 1
x = 3
while x**2 <= n:
c = 0
while not n % x:
prime[x] += 1
... | N, M = list(map(int, input().split()))
MOD = 10**9+7
class Comb:
def __init__(self, N):
self.fac = [1] * (N+1)
for i in range(2, N+1): self.fac[i] = self.fac[i-1] * i % MOD
def pow(self, a, b):
res = 1
while b:
if b & 1: res = res * a % MOD
... | p03253 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.