-
Notifications
You must be signed in to change notification settings - Fork 0
/
11444.d
89 lines (63 loc) · 1.28 KB
/
11444.d
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import std.stdio;
//import std.algorithm;
//import std.math;
//import std.conv;
//import std.numeric;
//import std.range;
//import std.array;
//import std.bigint;
//import std.string;
long w = 1000000007;
long[2][2] mul(long[2][2] A, long[2][2] B){
long s;
long[2][2] L;
foreach(i; 0..2){
long[2] a = A[i];
long[2] l;
foreach(j; 0..2){
long[2] b = [B[0][j], B[1][j]];
s = 0L;
foreach(k; 0..2){
s += (a[k]%w)*(b[k]%w);
}
l[j] = s%w;
}
L[i] = l;
}
return L;
}
bool[60] bin(long n){
bool[60] i60;
long k = 1152921504606846976L;
foreach_reverse(i; 0..61){
if(n >= k){
i60[i] = true;
n -= k;
}
k >>= 1;
}
return i60;
}
long sol(long n){
bool[60] B = bin(n);
long[2][2] K = [[1L,0L],[0L,1L]];
long[2][2] L = [[1L,1L],[1L,0L]];
int l=59;
while(!(B[l])){
l--;
}
foreach(i; 0..l+1){
if (i){
L = mul(L, L);
}
if (B[i]){
K = mul(K, L);
}
}
return K[0][1];
}
void main(){
long n;
scanf("%ld", &n);
writeln(sol(n));
}