結果

問題 No.1287 えぬけー
ユーザー shotoyooshotoyoo
提出日時 2020-11-13 21:52:52
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 303 ms / 2,000 ms
コード長 1,241 bytes
コンパイル時間 257 ms
コンパイル使用メモリ 87,200 KB
実行使用メモリ 78,300 KB
最終ジャッジ日時 2023-09-30 02:49:06
合計ジャッジ時間 2,818 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,328 KB
testcase_01 AC 72 ms
71,504 KB
testcase_02 AC 71 ms
71,160 KB
testcase_03 AC 68 ms
71,508 KB
testcase_04 AC 69 ms
71,332 KB
testcase_05 AC 299 ms
78,300 KB
testcase_06 AC 297 ms
78,212 KB
testcase_07 AC 303 ms
78,296 KB
testcase_08 AC 290 ms
78,276 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


def factor(n, m=None):
    # mを与えると、高々その素因数まで見て、残りは分解せずにそのまま出力する
    f = {}
    tmp = n
    M = int(-(-n**0.5//1))+1
    if m is not None:
        M = min(m+1, M)
    for i in range(2, M+1):
        if tmp<i:
            break
        if tmp%i==0:
            cnt=0
            while tmp%i==0:
                cnt+=1
                tmp //= i
            f[i] = cnt
    if tmp!=1:
        f[tmp] = 1
    if not f:
        f[n] = 1
    return f
def gcd2(a, b):
    """a*x + b*y = gcd(a,b)なるx,yも求める
    """
    l = []
    while b:
        l.append(divmod(a,b))
        a, b = b, a%b
    x, y = 1, 0
    for aa,bb in l[::-1]:
        x, y = y, x - aa*y
    return a, x, y
def modinv(x, M):
    """素数ではないM、Mと互いに素なxに対し
    x * y == 1 mod M なるyを求める
    """
    a,xx,yy = gcd2(x,M)
    return a,xx%M

def sub(x,k):
    _,j = modinv(k, M-1)
    ans = pow(x, j, M)
    return ans
M = 10**9+7
t = int(input())
for i in range(t):
    x,k = map(int, input().split())
    print(sub(x,k))
0