LIST09: Các số nguyên tố

Xem dạng PDF

Gửi bài giải

Điểm: 1,00 (OI)
Giới hạn thời gian: 1.0s
Giới hạn bộ nhớ: 64M
Input: stdin
Output: stdout

Dạng bài
Ngôn ngữ cho phép
C++, Pascal, Python


Bình luận

Hãy đọc nội quy trước khi bình luận.



  • 1
    AnCTPP_01  đã bình luận lúc 7, Tháng 12, 2025, 2:52

    include <bits/stdc++.h>

    using namespace std; bool isPrime(int x) { if (x < 2) return false; if (x == 2 || x == 3) return true; if (x % 2 == 0) return false; for (int i = 3; i * 1LL * i <= x; i += 2) { if (x % i == 0) return false; } return true; } int main() { int n; cin >> n; vector<int> a(n), primes; for (int i = 0; i < n; i++) { cin >> a[i]; if (isPrime(a[i])) primes.push_back(a[i]); } sort(primes.begin(), primes.end(), greater<int>()); cout << primes.size() << endl; for (int x : primes) cout << x << " "; }