Submission #445756

# Submission time Handle Problem Language Result Execution time Memory
445756 2021-07-19T13:38:03 Z hamerin Phibonacci (kriii2_P) PyPy 3
1 / 4
58 ms 18524 KB
M = int(1e9 + 7)
mod = M**16


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)
# Verdict Execution time Memory Grader output
1 Correct 44 ms 18180 KB Output is correct
2 Correct 41 ms 18240 KB Output is correct
3 Correct 41 ms 18172 KB Output is correct
4 Correct 42 ms 18188 KB Output is correct
5 Correct 45 ms 18148 KB Output is correct
6 Correct 41 ms 18144 KB Output is correct
7 Correct 41 ms 18112 KB Output is correct
8 Correct 41 ms 18148 KB Output is correct
9 Correct 42 ms 18124 KB Output is correct
10 Correct 42 ms 18212 KB Output is correct
11 Correct 45 ms 18244 KB Output is correct
12 Correct 41 ms 18140 KB Output is correct
13 Correct 43 ms 18188 KB Output is correct
14 Correct 42 ms 18168 KB Output is correct
15 Correct 42 ms 18132 KB Output is correct
16 Correct 52 ms 18132 KB Output is correct
17 Correct 42 ms 18128 KB Output is correct
18 Correct 42 ms 18172 KB Output is correct
19 Correct 41 ms 18160 KB Output is correct
20 Correct 46 ms 18192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 56 ms 18340 KB Output is correct
2 Correct 49 ms 18524 KB Output is correct
3 Correct 44 ms 18432 KB Output is correct
4 Correct 44 ms 18316 KB Output is correct
5 Correct 45 ms 18468 KB Output is correct
6 Correct 45 ms 18316 KB Output is correct
7 Correct 44 ms 18356 KB Output is correct
8 Correct 45 ms 18428 KB Output is correct
9 Correct 48 ms 18380 KB Output is correct
10 Correct 57 ms 18296 KB Output is correct
11 Correct 43 ms 18308 KB Output is correct
12 Correct 43 ms 18380 KB Output is correct
13 Correct 45 ms 18308 KB Output is correct
14 Correct 54 ms 18404 KB Output is correct
15 Correct 45 ms 18432 KB Output is correct
16 Correct 55 ms 18464 KB Output is correct
17 Correct 58 ms 18332 KB Output is correct
18 Correct 45 ms 18316 KB Output is correct
19 Incorrect 44 ms 18188 KB Output isn't correct
20 Halted 0 ms 0 KB -