Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <fstream>
- using namespace std;
- const char DF[] = "duom.txt";
- const char AF[] = "ats.txt";
- void read(ifstream &df);
- void doit();
- void release(ofstream &af);
- int n;
- int notPrimes = 0;
- int X[50];
- int main()
- {
- n=0;
- ifstream df(DF);
- read(df);
- doit();
- ofstream af(AF);
- release(af);
- return 0;
- }
- void read(ifstream &df)
- {
- df >> n;
- for (int i = 0; i < n; i++)
- df >> X[i];
- }
- void doit()
- {
- for (int i = 0; i < n; i++)
- {
- for (int p = 2; p*p <= X[i]; p++)
- {
- if (X[i] % p == 0)
- {
- cerr << X[i] << endl;
- X[notPrimes] = X[i];
- notPrimes++;
- p = X[i]; // cia kad breiko nereiketu
- }
- }
- }
- }
- void release(ofstream &af)
- {
- for (int i = 0; i < notPrimes; i++)
- af << X[i] << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement