我有一個函數可以調用自己接近無限的次數,但它確實有一個結束。它計算數學公式(在特):大規模遞歸函數中的分割錯誤
當x<a
:
g_{a}(x)=1
當x>=a
:
g_{a}(x)=g_{a}(x-1)+g_a(x-a)
這是我的代碼(C++):
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <cmath>
using namespace std;
double g(double a, double x){
if (x>=a) return (g(a,x-1)+g(a,x-a));
else if (x<a) return 1;
return 0;
}
int main(){cout << g(sqrt(10000019),10000019);}
我與g(sqrt(10000019),10000019);
聯繫3210如何停止SEGFAULT?
使用a和x的值是否會得到SEGFAULT? –
而且,你不能發佈[MCVE](http://stackoverflow.com/help/mcve)嗎? –
順便說一下,這是Ackermann_function,我正確嗎?如果是,那麼我懷疑你可以停止SEGFAULT。 – gjha