我必須找到(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;
}
}
現在,我無法理解如何照顧模數條件。有人請幫助。