#include using namespace std; void solve(int &i, int sum, int Max) { if(sum + i >= Max) return ; i++; solve(i,sum+i,Max); } int main() { int m = 1; solve(m,0,1000); printf("%d",m); }
C/C++ code#include using namespace std; void solve(int &i, int sum, int Max) { if(sum + i >= Max) return ; i++; solve(i,sum+i,Max); } int main() { int m = 1; solve(m,0,1000); printf("%d",m); } 输出: 44
int solve(int curr, int sum, int Max) { return curr+sum>=Max ? curr-1 : solve(curr+1, curr+sum, Max); }