我必须找到(1 + sqrt(3))^ n的值,其中n < 10^9。因为这个数字可能非常大,我们必须打印ans%1000000007。 我已经为此写了下面的函数。模数运算符在处理双精度时的用法
double power(double x, int y)
{
double temp;
if(y == 0)
return 1;
temp = power(x, y/2);
if (y%2 == 0)
return temp*temp;
else
{
if(y > 0)
return x*temp*temp;
else
return (temp*temp)/x;
}
}
现在,我无法理解如何照顾模数条件。有人请帮助。