提交时间:2024-11-09 22:22:33
运行 ID: 56230
#include<iostream> using namespace std; int main(){ int fib[45], n; fib[0] = 1; fib[1] = 1; cin >> n; if (n <= 40){ for (int i=2; i<n; i++){ fib[i] = fib[i-1] + fib[i-2]; bool flag = true; for (int j=2; j<fib[i]; j++){ if (fib[i] % j == 0){ flag = false; break; } } if (flag){ cout << fib[i] << " "; } } cout << endl; for (int i=0; i<n; i++){ cout << fib[i] << " "; } } return 0; }