結果
問題 | No.2365 Present of good number |
ユーザー | lloyz |
提出日時 | 2023-06-30 22:41:41 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 48 ms / 2,000 ms |
コード長 | 1,812 bytes |
コンパイル時間 | 248 ms |
コンパイル使用メモリ | 82,232 KB |
実行使用メモリ | 66,716 KB |
最終ジャッジ日時 | 2024-07-07 10:32:37 |
合計ジャッジ時間 | 2,992 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 39 |
ソースコード
from collections import defaultdict IsPrime = [True for _ in range(10**5 + 1)] IsPrime[0] = IsPrime[1] = False Primes = [] for i in range(2, 10**5 + 1): if IsPrime[i]: Primes.append(i) for j in range(i * i, 10**5 + 1, i): IsPrime[j] = False n, k = map(int, input().split()) mod = 10**9 + 7 P = defaultdict(int) seen = set() for prime in Primes: while n % prime == 0: seen.add(prime) P[prime] += 1 n //= prime if n == 1: break C = [(p, c) for p, c in P.items()] while k > 0: if len(seen) == 2 and 2 in seen and 3 in seen: break if len(seen) == 1 and (2 in seen or 3 in seen): break k -= 1 P = defaultdict(int) seen = set() for p, c in C: p += 1 if IsPrime[p]: seen.add(p) P[p] += c P[p] %= mod - 1 else: for prime in Primes: while p % prime == 0: seen.add(prime) P[prime] += c P[prime] %= mod - 1 p //= prime if p == 1: break C = [(p, c) for p, c in P.items()] if k > 0: q, r = divmod(k, 2) P = defaultdict(int) for p, c in C: if p == 2: if r == 0: P[2] += c * pow(2, q, mod - 1) P[2] %= mod - 1 else: P[3] += c * pow(2, q, mod - 1) P[3] %= mod - 1 else: if r == 0: P[3] += c * pow(2, q, mod - 1) P[3] %= mod - 1 else: P[2] += c * pow(2, q + 1, mod - 1) P[2] %= mod - 1 C = [(p, c) for p, c in P.items()] ans = 1 for p, c in C: ans *= pow(p, c, mod) ans %= mod print(ans)