hi,
3 8 12 17 22 28 35 44 56this is the series1
5 4 5 5 6 7 9 12 this is the consecutive term difference
series2
-1 1 0 1 1 2 3 this is further the consecutive term
difference series3
the series3 is forming a fibonacci series ..
baesd on this you have to find the Nth term of the first series.
where 1<=N<10^11
i am able to solve it in o(n) ..the only problem is that the large value
of n...
with my logic i can get value only up to 99th term...
here is my code
#include
#include
#include
int main()
{
int t;long long n;
scanf("%d",&t);
while(t)
{
long long sum=5,temp=5,a=-1,b=1,c,j;
scanf("%lld",&n);
if(n==1)
printf("%lld\n",3);
if(n==2)
{
printf("%lld\n",8);
}
else
{
j=n-2;
while(j)
{
temp=temp+a;
sum=sum+temp;
c=a+b;
a=b;
b=c;
j--;
}
sum=sum+3;
printf("%lld\n",sum);
}
t--;
}
return 0;
}
please suggest the modifications...
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.