結果
問題 | No.1659 Product of Divisors |
ユーザー | None |
提出日時 | 2021-10-05 07:24:26 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 47 ms / 2,000 ms |
コード長 | 3,411 bytes |
コンパイル時間 | 266 ms |
コンパイル使用メモリ | 82,196 KB |
実行使用メモリ | 57,860 KB |
最終ジャッジ日時 | 2024-07-23 02:31:50 |
合計ジャッジ時間 | 2,231 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 45 ms
55,888 KB |
testcase_01 | AC | 46 ms
56,484 KB |
testcase_02 | AC | 45 ms
56,640 KB |
testcase_03 | AC | 46 ms
56,276 KB |
testcase_04 | AC | 45 ms
55,896 KB |
testcase_05 | AC | 46 ms
57,360 KB |
testcase_06 | AC | 45 ms
56,988 KB |
testcase_07 | AC | 46 ms
56,352 KB |
testcase_08 | AC | 46 ms
57,304 KB |
testcase_09 | AC | 45 ms
56,448 KB |
testcase_10 | AC | 45 ms
56,128 KB |
testcase_11 | AC | 44 ms
56,208 KB |
testcase_12 | AC | 45 ms
57,860 KB |
testcase_13 | AC | 45 ms
55,684 KB |
testcase_14 | AC | 46 ms
55,684 KB |
testcase_15 | AC | 45 ms
55,896 KB |
testcase_16 | AC | 46 ms
55,896 KB |
testcase_17 | AC | 47 ms
57,256 KB |
testcase_18 | AC | 45 ms
56,196 KB |
testcase_19 | AC | 46 ms
56,000 KB |
testcase_20 | AC | 45 ms
56,380 KB |
testcase_21 | AC | 47 ms
56,736 KB |
testcase_22 | AC | 46 ms
57,300 KB |
testcase_23 | AC | 46 ms
55,684 KB |
testcase_24 | AC | 45 ms
56,752 KB |
ソースコード
def combination(n, r, MOD=10**9+7): """ O(r) """ if not 0 <= r <= n: return 0 r = min(r, n - r) numerator = reduce(lambda x, y: x * y % MOD, range(n, n - r, -1), 1) denominator = reduce(lambda x, y: x * y % MOD, range(1, r + 1), 1) return numerator * pow(denominator, MOD - 2, MOD) % MOD def combination2(n, r): """ O(r) """ if not 0 <= r <= n: return 0 r = min(r, n - r) numerator = reduce(lambda x, y: x * y, range(n, n - r, -1), 1) denominator = reduce(lambda x, y: x * y, range(1, r + 1), 1) return numerator // denominator ############################################################################################## import sys input = sys.stdin.readline from functools import reduce def is_prime_MR(n): if n in [2, 7, 61]: return True if n < 2 or n % 2 == 0: return False d = n - 1 d = d // (d & -d) L = [2, 7, 61] if n < 1<<32 else [2, 3, 5, 7, 11, 13, 17] if n < 1<<48 else [2, 3, 5, 7, 11, 13, 17, 19, 23] if n < 1<<61 else [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37] for a in L: t = d y = pow(a, t, n) if y == 1: continue while y != n - 1: y = (y * y) % n if y == 1 or t == n - 1: return False t <<= 1 return True def prime_counter(n): i = 2 ret = {} mrFlg = 0 while i*i <= n: k = 0 while n % i == 0: n //= i k += 1 if k: ret[i] = k i += 1 + i%2 if i == 101 and n >= 2**20: while n > 1: if is_prime_MR(n): ret[n], n = 1, 1 else: mrFlg = 1 j = _find_factor_rho(n) k = 0 while n % j == 0: n //= j k += 1 ret[j] = k if n > 1: ret[n] = 1 if mrFlg > 0: ret = {x: ret[x] for x in sorted(ret)} return ret def divisors(n): """ O(x^1/4) O(10**9)の整数10**4個の約数列挙が可能 """ primes=prime_counter(n) P=set([1]) for key, value in primes.items(): Q=[] for p in P: for k in range(value+1): Q.append(p*pow(key,k)) P|=set(Q) P = sorted(list(P)) # 速度が欲しい時は消す return P def _find_factor_rho(n): m = 1 << n.bit_length() // 8 + 1 for c in range(1, 99): f = lambda x: (x * x + c) % n y, r, q, g = 2, 1, 1, 1 while g == 1: x = y for i in range(r): y = f(y) k = 0 while k < r and g == 1: ys = y for i in range(min(m, r-k)): y = f(y) q = q * abs(x - y) % n g = gcd(q, n) k += m r <<= 1 if g == n: g = 1 while g == 1: ys = f(ys) g = gcd(abs(x-ys), n) if g < n: if is_prime_MR(g): return g elif is_prime_MR(n//g): return n//g ############################################################################################## import sys from math import gcd input = sys.stdin.readline MOD = 10**9+7 N,K=map(int, input().split()) res=1 for p,cnt in prime_counter(N).items(): res*=combination(K+cnt,cnt,MOD) res%=MOD print(res)