結果
| 問題 |
No.2365 Present of good number
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-06-30 22:07:02 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 87 ms / 2,000 ms |
| コード長 | 1,121 bytes |
| コンパイル時間 | 252 ms |
| コンパイル使用メモリ | 82,304 KB |
| 実行使用メモリ | 80,000 KB |
| 最終ジャッジ日時 | 2024-07-07 09:54:09 |
| 合計ジャッジ時間 | 4,582 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 39 |
ソースコード
mod = 10**9+7
n,k = map(int, input().split())
m = 10**5+100
a = [-1] * m
p = []
d = dict()
for i in range(2, m):
if a[i] == -1:
d[i] = len(p)
p.append(i)
for j in range(i, m, i):
a[j] = i
pl = len(p)
from collections import defaultdict
def f(x):
res = defaultdict(int)
while x != 1:
q = a[x]
c = 0
while x % q == 0:
x //= q
c += 1
res[q] = c
return res
def g(a, b, k):
if k % 2 == 0:
return pow(2, pow(2, k//2, mod-1)*a, mod)*pow(3, pow(2, k//2, mod-1)*b, mod)%mod
else:
return pow(2, pow(2, (k+1)//2, mod-1)*b, mod)*pow(3, pow(2, k//2, mod-1)*a, mod)%mod
b = []
for q in p:
if q < 10**5+10:
b.append(f(q+1))
c = f(n)
for i in range(k):
if len(c) <= 2 and sum([x == 2 or x == 3 for x in c]) == len(c):
print(g(c[2], c[3], k-i))
exit()
nxt = defaultdict(int)
for q in c:
for r in b[d[q]]:
nxt[r] += b[d[q]][r] * c[q]
c = nxt
#print(c)
ans = 1
for i in c:
ans *= pow(i, c[i], mod)
ans %= mod
print(ans)