結果
問題 | No.2365 Present of good number |
ユーザー |
|
提出日時 | 2023-06-30 22:42:26 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,237 bytes |
コンパイル時間 | 264 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 55,680 KB |
最終ジャッジ日時 | 2024-07-07 10:33:38 |
合計ジャッジ時間 | 3,492 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 37 WA * 2 |
ソースコード
import sys, time, randomfrom collections import deque, Counter, defaultdictinput = lambda: sys.stdin.readline().rstrip()ii = lambda: int(input())mi = lambda: map(int, input().split())li = lambda: list(mi())from math import gcddef isprime(n):if n <= 2:return n == 2if n % 2 == 0:return Falses = 0t = n - 1while t % 2 == 0:s += 1t //= 2for a in [2,325,9375,28178,450775,9780504,1795265022]:if a >= n:breakx = pow(a, t, n)if x == 1 or x == n - 1:continuefor _ in range(s):x = (x * x) % nif x == n - 1:breakif x == n - 1:continuereturn Falsereturn Truedef Pollad(N):if N % 2 == 0:return 2if isprime(N):return Ndef f(x):return (x * x + 1) % Nstep = 0while True:step += 1x = stepy = f(x)while True:p = gcd(y - x + N, N)if p == 0 or p == N:breakif p != 1:return px = 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:continuep = Pollad(now)if p == now:ret.append(p)else:q.append(p)q.append(now // p)return Counter(ret)mod = 10 ** 9 + 7n, k = mi()while k > 0:now = nC = Primefact(now)S = set(C.keys())S.discard(2)S.discard(3)if S:k -= 1n = 1for v, c in C.items():n *= pow(v + 1, c)else:breakif k == 0:ans = nelse:p = 0while n % 2 == 0:p += 1n //= 2q = 0while n % 3 == 0:q += 1n //= 3q = (pow(2, (k + 1) // 2, mod - 1) * q + mod - 1) % (mod - 1)p = (pow(2, k // 2, mod - 1) * p + mod - 1) % (mod - 1)if k % 2:ans = pow(2, q, mod) * pow(3, p, mod)ans %= modelse:ans = pow(2, p, mod) * pow(3, q, mod)ans %= modprint(ans)