Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
16
Task/Fibonacci-sequence/C-sharp/fibonacci-sequence-11.cs
Normal file
16
Task/Fibonacci-sequence/C-sharp/fibonacci-sequence-11.cs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
private static Matrix M;
|
||||
private static readonly Matrix N = new Matrix(1,1,1,0);
|
||||
|
||||
public static ulong Fib(uint n) {
|
||||
M = new Matrix(1,0,0,1);
|
||||
MatrixPow(n-1);
|
||||
return (ulong)M[0][0];
|
||||
}
|
||||
|
||||
private static void MatrixPow(double n){
|
||||
if (n > 1) {
|
||||
MatrixPow(n/2);
|
||||
M *= M;
|
||||
}
|
||||
if (n % 2 == 0) M *= N;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue