#include<iostream>
#include<cstring>
using namespace std;
using ll = __int128;
const int LIMIT = 126, M = 1e9 + 7;
const ll MOD = (long long)M * M;
struct _mt {
ll m[2][2], t[2][2];
_mt() {
memset(m, 0, sizeof m);
memset(t, 0, sizeof t);
}
void E() { for (int i = 0; i < 2; i++) t[i][i] = m[i][i] = 1; }
_mt operator*(const _mt& o) {
_mt r;
int i, j, k;
for (i = 0; i < 2; i++)for (j = 0; j < 2; j++) for (k = 0; k < 2; k++) {
r.m[i][j] = (r.m[i][j] + m[i][k] * o.m[k][j]) % M;
r.t[i][j] = (r.t[i][j] + t[i][k] * o.t[k][j]) % MOD;
}
return r;
}
}F[LIMIT], NK, K;
ll _pow(ll a, ll n, ll Mod) {
if (n == 1) return a;
ll h = _pow(a, n >> 1, Mod);
return (h * h % Mod) * (n % 2 ? a : 1) % Mod;
}
int main() {
ll n, k, A, B, i, nk, bitset_v = 1, x, y;
long long tN, tK;
cin >> tN >> tK;
n = tN, k = tK;
F[0].m[0][0] = F[0].m[0][1] = F[0].m[1][0] = 1;
NK.E(); K.E();
nk = k * n;
for (i = 1; i < LIMIT; i++) F[i] = F[i - 1] * F[i - 1];
for (i = 0; i < LIMIT; i++) {
if ((bitset_v << i) & nk) NK = NK * F[i];
if ((bitset_v << i) & k) K = K * F[i];
}
if(K.m[0][1]){
x = K.m[0][1];
y = NK.m[0][1];
A = NK.m[0][1] * _pow(x, M - 2, M) % M;
} else {
x = K.t[0][1];
y = NK.t[0][1];
A = y * _pow(x, MOD - 2, MOD) % M;
}
B = (NK.m[1][1] - A * K.m[1][1] % M + M) % M;
cout << (long long)A << ' ' << (long long)B;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
4 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
380 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
5 ms |
376 KB |
Output is correct |
18 |
Correct |
4 ms |
376 KB |
Output is correct |
19 |
Correct |
5 ms |
376 KB |
Output is correct |
20 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
380 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
6 ms |
256 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
5 ms |
380 KB |
Output is correct |
18 |
Correct |
4 ms |
376 KB |
Output is correct |
19 |
Incorrect |
5 ms |
376 KB |
Output isn't correct |
20 |
Halted |
0 ms |
0 KB |
- |