#include<bits/stdc++.h>
using namespace std;
using ll=long long;
struct mat{
ll a,b;
ll c,d;
mat(ll x=0,ll y=0,ll z=0,ll w=0):a(x),b(y),c(z),d(w){}
};
const ll mod=1e9+7;
mat operator*(mat x,mat y){
return mat((x.a*y.a%mod+x.b*y.c%mod+mod)%mod, (x.a*y.b%mod+x.b*y.d%mod+mod)%mod,
(x.c*y.a%mod+x.d*y.c%mod+mod)%mod, (x.c*y.b%mod+x.d*y.d%mod+mod)%mod
);
}
mat matPow(mat x,ll n){
if(n==0)return mat(1,0,0,1);
if(n==1)return x;
if(n&1)return matPow(x*x,n/2)*x;
return matPow(x*x,n/2);
}
ll ipow(ll x,ll n){
if(n==0)return 1;
if(n==1)return x;
if(n&1)return ipow(x*x%mod,n/2)*x%mod;
return ipow(x*x%mod,n/2)%mod;
}
int main(void){
ll n,k;
cin>>n>>k;
if(!n||!k){
cout<<"0 1";
return 0;
}
mat x=matPow(matPow({1,1,1,0},n),k),y=matPow({1,1,1,0},k);
ll a=x.b*ipow(y.b,mod-2)%mod;
if(y.b==0){
if(n==1){
a=1;
}
else{
mat z=matPow({1,1,1,0},k-1)*mat({4,3,3,1});
ll t=z.d;
ll pl=mod-1;
mat w=matPow({t,pl,1,0},n);
a=w.d;
}
}
ll b=(x.d-a*y.d%mod+mod)%mod;
cout<<a<<" "<<b<<"\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
256 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
256 KB |
Output is correct |
6 |
Correct |
5 ms |
256 KB |
Output is correct |
7 |
Correct |
5 ms |
256 KB |
Output is correct |
8 |
Correct |
5 ms |
256 KB |
Output is correct |
9 |
Correct |
5 ms |
256 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
256 KB |
Output is correct |
12 |
Correct |
5 ms |
296 KB |
Output is correct |
13 |
Correct |
5 ms |
256 KB |
Output is correct |
14 |
Correct |
5 ms |
256 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
256 KB |
Output is correct |
17 |
Correct |
5 ms |
256 KB |
Output is correct |
18 |
Correct |
5 ms |
360 KB |
Output is correct |
19 |
Correct |
5 ms |
376 KB |
Output is correct |
20 |
Correct |
5 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
256 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
256 KB |
Output is correct |
7 |
Correct |
5 ms |
256 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
256 KB |
Output is correct |
10 |
Correct |
5 ms |
256 KB |
Output is correct |
11 |
Correct |
5 ms |
256 KB |
Output is correct |
12 |
Correct |
5 ms |
256 KB |
Output is correct |
13 |
Correct |
5 ms |
256 KB |
Output is correct |
14 |
Correct |
5 ms |
256 KB |
Output is correct |
15 |
Correct |
5 ms |
256 KB |
Output is correct |
16 |
Correct |
5 ms |
256 KB |
Output is correct |
17 |
Correct |
5 ms |
256 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
19 |
Incorrect |
5 ms |
256 KB |
Output isn't correct |
20 |
Halted |
0 ms |
0 KB |
- |