Pages

Wednesday, October 7, 2009

Big Mod (uva#374)

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;
}
  

Fibonacci using quick matrix

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;
}

Fibonacci using dynamic program

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;
}

Fibonacci using normal recursion

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);
}

Ins and outs of Fibonacci numbers

here is a describe document on fibonacci number. Almost everything of it....

click here to view/download

Ins and outs of Fibonacci numbers

here is a describe document on fibonacci number. Almost everything of it....

click here to view/download

Divisibility rules

here is another important topics on the various rules of divisibility.

click here to download

Divisibility rules

here is another important topics on the various rules of divisibility.

click here to download

Bit wise operator

Using of Bit wise operators instead of any other mathematical operators is much more faster. here is a document of its uses.

click here to download

Bit wise operator

Using of Bit wise operators instead of any other mathematical operators is much more faster. here is a document of its uses.

click here to download