Run ID Author Problem Lang Verdict Time Memory Code Length Submit Time
58634 teacher_lu 斐波那契数列里的质数 C++ Accepted 2 MS 256 KB 588 2024-12-13 18:56:54

Tests(5/5):


#include<bits/stdc++.h> using namespace std; bool f(int n) { if(n == 1) return 0; for(int i = 2; i < n; i++) { if(n % i == 0) { // 找到因数 return 0; } } // 在2~n-1中没有找到因数,不是合数,就是质数 return 1; } long long a[50]; int main() { int n; cin >> n; a[1] = 1; a[2] = 1; for(int i = 3; i <= n; i++) { a[i] = a[i-1] + a[i-2]; } for(int i = 1; i <= n; i++) { if(f(a[i]) == 1) cout << a[i] << " "; } cout << endl; for(int i = 1; i <= n; i++) { cout << a[i] << " "; } return 0; }


Judgement Protocol: