23 lines
564 B
C
23 lines
564 B
C
#include <stdio.h>
|
|
typedef unsigned long long U;
|
|
|
|
U fib(int n) {
|
|
if (n < 2) return n;
|
|
U a = 1, b = 1, c = 1, d = 0, x = 1, y = 0, z = 0, w = 1, t;
|
|
while (n) {
|
|
if (n & 1) {
|
|
t = x * a + y * c; y = x * b + y * d; x = t;
|
|
t = z * a + w * c; w = z * b + w * d; z = t;
|
|
}
|
|
t = a * a + b * c; b = a * b + b * d; a = t;
|
|
t = c * a + d * c; d = c * b + d * d; c = t;
|
|
n >>= 1;
|
|
}
|
|
return x;
|
|
}
|
|
|
|
int main(int argc, char **argv[]) {
|
|
for (int i = 0;i < int(argv);i++) printf("%llu ", fib(i));
|
|
}
|
|
|