Harcourt Butler Technical University 2025
My Stats
EXP gained
7113
Level
6 (Specialist)
Community stats
Discussions
0
1
Know more
308
Total problems solved
302
Easy
5
Moderate
1
Hard
0
Ninja

Current streak:

0 days

Longest streak:

9 days

Less

More

Achievements
1
Ronin
Topics
Math
1
Samurai
Guided path
Basics of C++
1
Sensei
Guided path
Fundamentals of Html
Discussions
N-th Fibonacci Number
Interview problems

#include <bits/stdc++.h>  const int m = 1000000007;

void multiply(long long F[2][2], long long M[2][2]) {    long long x = ((F[0][0] % m * M[0][0] % m) % m + (F[0][1] % m * M[1][0] % m) % m) % m;    long long y = ((F[0][0] % m * M[0][1] % m) % m + (F[0][1] % m * M[1][1] % m) % m) % m;    long long z = ((F[1][0] % m * M[0][0] % m) % m + (F[1][1] % m * M[1][0] % m) % m) % m;    long long w = ((F[1][0] % m * M[0][1] % m) % m + (F[1][1] % m * M[1][1] % m) % m) % m;

F[0][0] = x;    F[0][1] = y;    F[1][0] = z;    F[1][1] = w; }

void power(long long F[2][2], long long n) {    if (n == 0 || n == 1)        return;

long long M[2][2] = {{1, 1}, {1, 0}};

power(F, n / 2);    multiply(F, F);

if (n % 2 != 0)        multiply(F, M); }

long long fib(long long n) {    long long F[2][2] = {{1, 1}, {1, 0}};    if (n == 0)        return 0;    power(F, n - 1);

return F[0][0]; } int fibonacciNumber(int N){    // Write your code here. return (int)fib(N); }

ryzen234
Published On 31-Oct-2023
280 views
0 replies