Jump to content

Fibonacci difficult question

- - - - -

  • Please log in to reply
1 reply to this topic

#1
skd

skd

    Newbie

  • Members
  • Pip
  • 3 posts
find summation f(4*i-1) where 1<=i<=10^15.

Here is my code ....which is taking a lot of time and not giving the ans.
please help...


#include<stdio.h>

#include<stdlib.h>

#include<string.h>

#define CONSTANT 1

long long conquer_fibonacci(long long n){

     long long 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*k*h + t;

            k=k*k + t;

            n=(long) n/2;}

     return j;}



int main()

{

	long long a=0;

	long long sum=0;

 	long long i=1;

 long long limit= 1000000000000000;     

 while(i<=limit)

      {	

      	 

	a=conquer_fibonacci(4*i -1 );

sum+=a;

	

	


	i++;

      }

    //printf("%d %lu %lu %lu",i,a,sum,conquer_fibonacci(33));

  printf("%llu",sum);  

  getchar();

    return 0;

}



#2
fayyazlodhi

fayyazlodhi

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 403 posts
Certain aspects need to cleared first:

1. You want to sum every 4th fibonacci up to i? Is that the correct understanding

2. I see you loop through them all right, but at no point did i find exact fibonacci computation.

3. Your compute fib function is running a log n loop. It is very hard to figure out the intention of this loop because of variable names. Can you please explain a little what you are trying to achieve.

I would be able to debug and help with fixing the problem then.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users