File tree Expand file tree Collapse file tree 2 files changed +5
-5
lines changed
Expand file tree Collapse file tree 2 files changed +5
-5
lines changed Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ int main(int argc, char **argv) {
1717 std::cout << " fibonacci(20) = " << FIB20 << std::endl;
1818
1919 // TODO: 观察错误信息,修改一处,使代码编译运行
20- constexpr auto ANS_N = 100 ;
20+ constexpr auto ANS_N = 90 ;
2121 constexpr auto ANS = fibonacci (ANS_N);
2222 std::cout << " fibonacci(" << ANS_N << " ) = " << ANS << std::endl;
2323
Original file line number Diff line number Diff line change 33// TODO: 改正函数实现,实现正确的缓存优化斐波那契计算
44static unsigned long long fibonacci (int i) {
55 // TODO: 为缓存设置正确的初始值
6- static unsigned long long cache[128 ], cached;
6+ static unsigned long long cache[96 ], cached;
77 // TODO: 设置正确的循环条件
88 for (; false ; ++cached) {
99 cache[cached] = cache[cached - 1 ] + cache[cached - 2 ];
@@ -19,8 +19,8 @@ int main(int argc, char **argv) {
1919 ASSERT (fibonacci (3 ) == 2 , " fibonacci(3) should be 2" );
2020 ASSERT (fibonacci (10 ) == 55 , " fibonacci(10) should be 55" );
2121
22- auto fib100 = fibonacci (100 );
23- std::cout << " fibonacci(100 ) = " << fib100 << std::endl;
24- ASSERT (fib100 == 3736710778780434371 , " fibonacci(100 ) should be 3736710778780434371 " );
22+ auto fib90 = fibonacci (90 );
23+ std::cout << " fibonacci(90 ) = " << fib90 << std::endl;
24+ ASSERT (fib90 == 2880067194370816120 , " fibonacci(90 ) should be 2880067194370816120 " );
2525 return 0 ;
2626}
You can’t perform that action at this time.
0 commit comments