mod = int(1e9+7)
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)
if Fk == 0:
print(-1)
exit(0)
A = (Fnk * ext_euc(Fk, mod)[1]) % mod
B = (Fnkm1 - A * Fkm1) % mod
print(A, B)
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
42 ms |
18212 KB |
Output is correct |
2 |
Correct |
38 ms |
18100 KB |
Output is correct |
3 |
Correct |
39 ms |
18128 KB |
Output is correct |
4 |
Correct |
38 ms |
18152 KB |
Output is correct |
5 |
Correct |
40 ms |
18292 KB |
Output is correct |
6 |
Correct |
40 ms |
18220 KB |
Output is correct |
7 |
Correct |
38 ms |
18212 KB |
Output is correct |
8 |
Correct |
38 ms |
18200 KB |
Output is correct |
9 |
Correct |
48 ms |
18176 KB |
Output is correct |
10 |
Correct |
41 ms |
18120 KB |
Output is correct |
11 |
Correct |
42 ms |
18132 KB |
Output is correct |
12 |
Correct |
38 ms |
18156 KB |
Output is correct |
13 |
Correct |
38 ms |
18184 KB |
Output is correct |
14 |
Correct |
38 ms |
18152 KB |
Output is correct |
15 |
Correct |
40 ms |
18236 KB |
Output is correct |
16 |
Correct |
39 ms |
18216 KB |
Output is correct |
17 |
Correct |
42 ms |
18120 KB |
Output is correct |
18 |
Correct |
38 ms |
18140 KB |
Output is correct |
19 |
Correct |
42 ms |
18212 KB |
Output is correct |
20 |
Correct |
41 ms |
18136 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
39 ms |
18180 KB |
Output is correct |
2 |
Correct |
42 ms |
18196 KB |
Output is correct |
3 |
Correct |
40 ms |
18212 KB |
Output is correct |
4 |
Correct |
40 ms |
18124 KB |
Output is correct |
5 |
Correct |
39 ms |
18200 KB |
Output is correct |
6 |
Correct |
40 ms |
18208 KB |
Output is correct |
7 |
Correct |
39 ms |
18128 KB |
Output is correct |
8 |
Correct |
40 ms |
18248 KB |
Output is correct |
9 |
Correct |
39 ms |
18124 KB |
Output is correct |
10 |
Correct |
49 ms |
18216 KB |
Output is correct |
11 |
Correct |
40 ms |
18116 KB |
Output is correct |
12 |
Correct |
43 ms |
18216 KB |
Output is correct |
13 |
Correct |
42 ms |
18100 KB |
Output is correct |
14 |
Correct |
40 ms |
18212 KB |
Output is correct |
15 |
Correct |
39 ms |
18200 KB |
Output is correct |
16 |
Correct |
41 ms |
18168 KB |
Output is correct |
17 |
Correct |
41 ms |
18124 KB |
Output is correct |
18 |
Correct |
51 ms |
18188 KB |
Output is correct |
19 |
Incorrect |
43 ms |
18212 KB |
Output isn't correct |
20 |
Halted |
0 ms |
0 KB |
- |