답안 #445755

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
445755 2021-07-19T13:37:17 Z hamerin Phibonacci (kriii2_P) PyPy 3
1 / 4
61 ms 18328 KB
M = int(1e9 + 7)
mod = M**3


def ext_euc(a, b):
    if b == 0:
        return (a, 1, 0)
    g, x, y = ext_euc(b, a % b)
    return (g, y, x-(a//b)*y)


def matmul(l, r):
    return [[(l[0][0]*r[0][0]+l[0][1]*r[1][0]) % mod, (l[0][0]*r[0][1]+l[0][1]*r[1][1]) % mod],
            [(l[1][0]*r[0][0]+l[1][1]*r[1][0]) % mod, (l[1][0]*r[0][1]+l[1][1]*r[1][1]) % mod]]


def fibo(n):
    if n == -1:
        return 1

    base = [[1, 1], [1, 0]]
    target = [[1, 0], [0, 1]]
    while n:
        if n % 2:
            target = matmul(target, base)
        base = matmul(base, base)
        n //= 2

    return target[0][1]


N, K = map(int, input().split())

Fnk = fibo(N*K)
Fk = fibo(K)
Fnkm1 = fibo(N*K-1)
Fkm1 = fibo(K-1)

while Fk % M == 0 and Fnk % M == 0:
    Fk /= M
    Fnk /= M

A = (Fnk * ext_euc(Fk, mod)[1]) % M
B = (Fnkm1 - A * Fkm1) % M
print(A, B)
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 18212 KB Output is correct
2 Correct 45 ms 18328 KB Output is correct
3 Correct 40 ms 18180 KB Output is correct
4 Correct 40 ms 18144 KB Output is correct
5 Correct 43 ms 18148 KB Output is correct
6 Correct 61 ms 18212 KB Output is correct
7 Correct 54 ms 18108 KB Output is correct
8 Correct 46 ms 18168 KB Output is correct
9 Correct 40 ms 18120 KB Output is correct
10 Correct 41 ms 18204 KB Output is correct
11 Correct 40 ms 18212 KB Output is correct
12 Correct 41 ms 18132 KB Output is correct
13 Correct 40 ms 18204 KB Output is correct
14 Correct 43 ms 18180 KB Output is correct
15 Correct 42 ms 18212 KB Output is correct
16 Correct 42 ms 18212 KB Output is correct
17 Correct 41 ms 18196 KB Output is correct
18 Correct 40 ms 18224 KB Output is correct
19 Correct 44 ms 18160 KB Output is correct
20 Correct 41 ms 18128 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 18212 KB Output is correct
2 Correct 45 ms 18200 KB Output is correct
3 Correct 45 ms 18212 KB Output is correct
4 Correct 43 ms 18264 KB Output is correct
5 Correct 42 ms 18268 KB Output is correct
6 Correct 42 ms 18240 KB Output is correct
7 Correct 43 ms 18268 KB Output is correct
8 Correct 42 ms 18164 KB Output is correct
9 Correct 44 ms 18272 KB Output is correct
10 Correct 43 ms 18148 KB Output is correct
11 Correct 53 ms 18140 KB Output is correct
12 Correct 56 ms 18136 KB Output is correct
13 Correct 42 ms 18256 KB Output is correct
14 Correct 43 ms 18212 KB Output is correct
15 Correct 45 ms 18176 KB Output is correct
16 Correct 44 ms 18208 KB Output is correct
17 Correct 42 ms 18176 KB Output is correct
18 Correct 42 ms 18180 KB Output is correct
19 Incorrect 42 ms 18148 KB Output isn't correct
20 Halted 0 ms 0 KB -