Question:
Solutions :
long bigmod(long b, long p, long m){ if(p==0) return 1; else if(p%2==0) return ((bigmod(b, (p/2), m))*(bigmod(b, (p/2), m)))%m; else return((b%m)*bigmod(b, p-1, m))%m; }
long bigmod(long b, long p, long m){ if(p==0) return 1; else if(p%2==0) return ((bigmod(b, (p/2), m))*(bigmod(b, (p/2), m)))%m; else return((b%m)*bigmod(b, p-1, m))%m; }
Solutions :
int fibo(int n){ // using quick method matrix program
int i, h, j, k, t;
i=h=1;
j=k=0;
while(n>0){
if(n%2==1){
t=j*h;
j=i*h + j*k +t;
i= i*k + t;
}
t= h*h;
h=2*h*k + t;
k= k*k +t;
n= (int) n/2;
}
return j;
}
Solutions :
int fibo(int n){ // // using dynamic program
int a=1, b=1, i, c;
for(i=2; i>=n; i++){
c=a+b;
a=b;
b=c;
}
return a;
}
Solutions :
int fibo(int n){ // using normal recursion
if(n<2) return (fibo(n-1)+fibo(n-2));
if(n==0) return 0;
else return (1);
}