emmmmm我好不容易做出來一道題結果被告知超時???完全不會優化啊qaq而且還覺得自己寫得超級棒呢qaq
問題描述
f(x) = 1 .... (x=1,2)
f(x) = f(x-1) + f(x-2) .... (x>2)
對於給定的整數 n 和 m,我們希望求出:
f(1) + f(2) + ... + f(n) 的值。但這個值可能非常大,所以我們把它對 f(m) 取模。
公式如下
但這個數字依然很大,所以需要再對 p 求模。
輸入格式
輸入為一行用空格分開的整數 n m p (0 < n, m, p < 10^18)
輸出格式
輸出為1個整數,表示答案
樣例輸入
2 3 5
樣例輸出 0
樣例輸入
15 11 29
樣例輸出 25
#include #define max 100
using namespace std;
static int sum=0;
int f(int n)
int main()
int sum2=0;
for(int i=1;i<=n;i++)
sum2+=f[i];
cout<
斐波那契數列 斐波那契數列python實現
斐波那契數列 fibonacci sequence 又稱 分割數列 因數學家列昂納多 斐波那契 leonardoda fibonacci 以兔子繁殖為例子而引入,故又稱為 兔子數列 指的是這樣乙個數列 1 1 2 3 5 8 13 21 34 在數學上,斐波納契數列以如下被以遞推的方法定義 f 1 ...
迴圈斐波那契數列 斐波那契數列應用
什麼是斐波那契數列 斐波那契數列指的是這樣乙個數列 1,1,2,3,5,8,13,21,34,55,89,144 這個數列從第3項開始,每一項都等於前兩項之和 台階問題 有一段樓梯有10級台階,規定每一步只能跨一級或兩級,要登上第10級台階有幾種不同的走法?這就是乙個斐波那契數列 登上第一級台階有一...
斐波那契堆
以下是實現的程式 肯定可以再優化的。include include include include using namespace std class node delete m child m child null class fibonacciheap node insert int key v...