Загрузка данных


#include <iostream>
#include <vector>
using namespace std;

int main() {
    int n;
    cout << "Введите N: ";
    cin >> n;

    vector<int> b;

    for (int c = 2; c <= n; ++c) {
        bool f = true;
        for (int d = 2; d < c; ++d) {
            if (c % d == 0) {
                f = false;
                break;
            }
        }
        if (f) {
            b.push_back(c);
        }
    }

    long long s = 0;
    long long m = 1;
    for (int e : b) {
        s += e;
        m *= e;
    }

    cout << "Простые числа: ";
    for (int e : b) {
        cout << e << " ";
    }
    cout << "\nСумма: " << s << "\n";
    cout << "Произведение: " << m << "\n";

    return 0;
}

#include <iostream>
#include <vector>
using namespace std;

int main() {
    int n;
    cout << "Введите N: ";
    cin >> n;

    vector<int> a;
    for (int i = 2; i <= n; ++i) {
        a.push_back(i);
    }

    vector<int> b;

    while (!a.empty()) {
        int c = a[0];
        b.push_back(c);

        vector<int> temp;
        for (int d : a) {
            if (d % c != 0) {
                temp.push_back(d);
            }
        }
        a = temp;
    }

    long long s = 0;
    long long m = 1;
    for (int e : b) {
        s += e;
        m *= e;
    }

    cout << "Простые числа: ";
    for (int e : b) {
        cout << e << " ";
    }
    cout << "\nСумма: " << s << "\n";
    cout << "Произведение: " << m << "\n";

    return 0;
}