-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFibonacci.Numbers(Pair)
More file actions
45 lines (26 loc) · 1.08 KB
/
Fibonacci.Numbers(Pair)
File metadata and controls
45 lines (26 loc) · 1.08 KB
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
/*Author Arpit Singh Verma*/
/*Recursive Approach of Fibonacci Numbers*/
/*Most important Fibonacci Numbers Imp for Cp*/
/*Cp-algorithms*/
#include"bits/stdc++.h"
using namespace std;
int main(){
//main code of the problem
//creating a pair of int And INT
pair<int,int> fib(int n){
if(n==0)
return {0,1};
auto p = fib(n >> 1);
int c = p.first * (2 * p.second * p.second);
int d = p.first * p.first + p.second * p.second;
if(n&1)
return {d,c+d};
else
return {c,d};
//the above code returns Fn and Fn+1 as a pair.
}
}
/*Contains main code to be implemented*/
//Anything in the number raise to power --->>>0<<<<--- is 1 so Here power is b and b == 0 therefore a = 1;
//DIVING B BY 2 and then performing the actions
/*----------->>>>>Jai Bhole <<<<<<<--------------*/