私はこの問題を解決しています:
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;
}
改善点を提案できますか?