include iostream include vector include valarray using namespace std c

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <iostream>
#include <vector>
#include <valarray>
using namespace std;
const long long MOD = 1000000007;
vector<valarray<long long>> operator*=(vector<valarray<long long>>& A, vector<valarray<long long>> B)
{
long long length = A.size();
vector<valarray<long long>> result(2, valarray<long long>(1, 2));
for (long long i = 0; i < length; i++)
{
for (long long j = 0; j < length; j++)
{
long long buf = 0;
for (long long k = 0; k < length; k++)
{
buf += A[i][k] * B[k][j];
}
result[i][j] = buf % MOD;
}
}
A = result;
return result;
}
vector<valarray<long long>> operator*(vector<valarray<long long>> A, vector<valarray<long long>> B)
{
return A *= B;
}
vector<valarray<long long>> pow(vector<valarray<long long>> A, long long n)
{
vector<valarray<long long>> start = A;
long long i = 1;
while (i*2 <= n)
{
A *= A;
i *= 2;
}
if (i == 1)
return A;
else
if (i == n)
return A;
else
return A * pow(start, n - i);
}
int main()
{
long long n;
cin >> n;
vector<valarray<long long>> mas(2, valarray<long long>(1, 2));
mas[1][1] = 0;
cout <<(pow(mas, n)[1][0]) << endl;
return 0;
}