#include <stdio.h>
#include <math.h>
int main ()
{int a,i=1,n,T;
scanf("%d",&T);
n=T;
int q[T+1];
while(T--)
{scanf("%d",&a);
q[i++]=(long)((1/sqrt(5))*((pow(((1+sqrt(5))/2),a+2)-pow(((1-sqrt(5))/2),a+2))-1))%1000000007;
}
for(i=1;i<=n;i++)
printf("%d\n",q[i]);}
运行结果:
此题我算出Sn了,可是在取模这里一直有问题。。。求解计算过程中怎么防止溢出
For each addition or multiplication, take the modulus
Use recursive calculations instead of general formulas.
Thank you to the two great gods ლ(╹ε╹ლ) for figuring it out
(a+b)%c==(a%c)+(b%c)
Same as multiplication
After comments, the correction should be: (a+b)%c==((a%c)+(b%c))%c