我正在解决这个问题:
G(n) is defined as G(n) = G(n-1) + f(4n-1) , for n > 0 and G(0) = 0 f(i) is ith Fibonacci number. Given n you need to evaluate G(n)
模 1000000007。
Input First line contains number of test cases t (t<40000). Each of the next t
行包含一个整数 n ( 0 <= n < 2^51)。
Output For each test case print G(n) modulo 1000000007. Example Input: 2 2 4 Output: 15 714
这是我写的代码:
typedef long long type;
#define check 1000000007
type x;
type y;
type f(type n)
{
return(ceil((pow(1.618,n) - pow(-0.618,n))/((sqrt(5)*1.0))));
}
type val(type n)
{
if(n==0)
return 0;
else
return (val(n-1)+f(4*n-1));
}
int main()
{
cin>>x;
while(x--)
{
cin>>y;
cout<<val(y)%check<<endl;
}
//getch();
return 0;
}
您能提出任何改进建议吗?