#include <iostream>
#include <cmath>
using namespace std;
bool is_prime(int n) {
if (n < 2) return false;
for (int i = 2; i <= sqrt(n); i++) {
if (n % i == 0) return false;
}
return true;
int main() {
int n;
cin >> n;
int x;
for (int i = 0; i < n; i++) {
cin >> x;
if (is_prime(x)) cout << x << endl;
return 0;
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
#include <iostream>
#include <cmath>
using namespace std;
bool is_prime(int n) {
if (n < 2) return false;
for (int i = 2; i <= sqrt(n); i++) {
if (n % i == 0) return false;
}
return true;
}
int main() {
int n;
cin >> n;
int x;
for (int i = 0; i < n; i++) {
cin >> x;
if (is_prime(x)) cout << x << endl;
}
return 0;
}