Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- ifstream in("elimin_prime.in");
- ofstream out ("elimin_prime.out");
- const int lim = -1000000005;
- int n;
- int ciur[9600];
- int nrPrime;
- int numere[100005];
- bool numbers[100005];
- void ciurul(int n){
- ciur[nrPrime++] = 1;
- numbers[1] = true;
- ciur[nrPrime++] = 2;
- for (int i = 2; i <= n; i += 2) {
- numbers[i] = true;
- }
- for (int i = 3; i <= n; i += 2) {
- if(!numbers[i]){
- ciur[nrPrime++] = i;
- for (int j = i; j <= n ; j += i) {
- numbers[j] = true;
- }
- }
- }
- }
- int main() {
- in >> n;
- ciurul(n);
- for (int i = 1; i <= n; ++i) {
- in >> numere[i];
- }
- bool ok = true;
- while (ok){
- ok = false;
- int indPoz = 0;
- int afis = 0;
- int dist = ciur[indPoz++];
- for (int i = 1; i <= n; ++i) {
- if(numere[i] != lim){
- afis++;
- ok = true;
- if(dist - afis == 0){
- out << numere[i] << " ";
- dist = ciur[indPoz++];
- numere[i] = lim;
- }
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement