Problem Statement
This problem is a programming version of Problem 2 from projecteuler.net
Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:
1,2,3,5,8,13,21,34,55,89,⋯
By considering the terms in the Fibonacci sequence whose values do not exceed N, find the sum of the even-valued terms.
Input Format
First line containsT that denotes the number of test cases. This is followed by T lines, each containing an integer, N .
Output Format
Print the required answer for each test case.
Constraints1≤T≤105
10≤N≤4×1016
Sample Input
Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:
Input Format
First line contains
Output Format
Print the required answer for each test case.
Constraints
Sample Input
2
10
100
Sample Output 10
44
MY SOLUTION:
#include<stdio.h>
int main()
{
long int testcase;
scanf("%lld",&testcase);
while(testcase--)
{
long long int value,fact=0,temp=0,odd=1,even=2,count=0;
scanf("%lld",&value);
temp=value;
while(temp--)
{
fact=odd+even;
odd=even;
even=fact;
if(value>fact)
{
if(fact%2==0)
count+=fact;
}
else
break;
}
printf("%lld\n",count+2);
}
return 0;
}