Problem-solving ideas
- Law after a number of two numbers before and
Reference Solution
-
Violence can be calculated directly
-
Note that the first number exceeds 50 represents the range of the int (2 ^ 31--1 = 2147483647), need long long,
#include <iostream> #include <vector> using namespace std; int main() { vector<long long> arr={1, 1}; for(int i = 2; i < 50; i++){ arr.push_back(arr[i-2] + arr[i-1]); // 注意vector可以用索引访问内容,但是不可以用索引修改内容!! } cout << arr[arr.size()-1] << endl; //size()返回的是vector中最后一个元素的下一个位置 return 0; }