結果
| 問題 |
No.2365 Present of good number
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-06-30 22:44:26 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,213 bytes |
| コンパイル時間 | 217 ms |
| コンパイル使用メモリ | 82,396 KB |
| 実行使用メモリ | 57,924 KB |
| 最終ジャッジ日時 | 2024-07-07 10:35:38 |
| 合計ジャッジ時間 | 2,689 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 37 WA * 2 |
ソースコード
import sys, time, random
from collections import deque, Counter, defaultdict
input = lambda: sys.stdin.readline().rstrip()
ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(mi())
from math import gcd
def isprime(n):
if n <= 2:
return n == 2
if n % 2 == 0:
return False
s = 0
t = n - 1
while t % 2 == 0:
s += 1
t //= 2
for a in [2,325,9375,28178,450775,9780504,1795265022]:
if a >= n:
break
x = pow(a, t, n)
if x == 1 or x == n - 1:
continue
for _ in range(s):
x = (x * x) % n
if x == n - 1:
break
if x == n - 1:
continue
return False
return True
def Pollad(N):
if N % 2 == 0:
return 2
if isprime(N):
return N
def f(x):
return (x * x + 1) % N
step = 0
while True:
step += 1
x = step
y = f(x)
while True:
p = gcd(y - x + N, N)
if p == 0 or p == N:
break
if p != 1:
return p
x = f(x)
y = f(f(y))
def Primefact(N):
if N == 1:
return []
q = []
q.append(N)
ret = []
while q:
now = q.pop()
if now == 1:
continue
p = Pollad(now)
if p == now:
ret.append(p)
else:
q.append(p)
q.append(now // p)
return Counter(ret)
mod = 10 ** 9 + 7
n, k = mi()
while k > 0:
now = n
C = Primefact(now)
S = set(C.keys())
S.discard(2)
S.discard(3)
if S:
k -= 1
n = 1
for v, c in C.items():
n *= pow(v + 1, c)
else:
break
if k == 0:
ans = n
else:
p = 0
while n % 2 == 0:
p += 1
n //= 2
q = 0
while n % 3 == 0:
q += 1
n //= 3
q = (pow(2, (k + 1) // 2, mod - 1) * q + mod - 1)
p = (pow(2, k // 2, mod - 1) * p + mod - 1)
if k % 2:
ans = pow(2, q, mod) * pow(3, p, mod)
ans %= mod
else:
ans = pow(2, p, mod) * pow(3, q, mod)
ans %= mod
print(ans)