Advertisement
Guest User

notPrime

a guest
Sep 25th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <fstream>
  4.  
  5. using namespace std;
  6.  
  7. const char DF[] = "duom.txt";
  8. const char AF[] = "ats.txt";
  9.  
  10. void read(ifstream &df);
  11. void doit();
  12. void release(ofstream &af);
  13.  
  14. int n;
  15. int notPrimes = 0;
  16. int X[50];
  17.  
  18. int main()
  19. {
  20.     n=0;
  21.     ifstream df(DF);
  22.     read(df);
  23.     doit();
  24.     ofstream af(AF);
  25.     release(af);
  26.     return 0;
  27. }
  28.  
  29. void read(ifstream &df)
  30. {
  31.     df >> n;
  32.     for (int i = 0; i < n; i++)
  33.         df >> X[i];
  34. }
  35.  
  36. void doit()
  37. {
  38.     for (int i = 0; i < n; i++)
  39.     {
  40.         for (int p = 2; p*p <= X[i]; p++)
  41.         {
  42.             if (X[i] % p == 0)
  43.             {
  44.                 cerr << X[i] << endl;
  45.                 X[notPrimes] = X[i];
  46.                 notPrimes++;
  47.                 p = X[i]; // cia kad breiko nereiketu
  48.             }
  49.         }
  50.     }
  51. }
  52.  
  53. void release(ofstream &af)
  54. {
  55.     for (int i = 0; i < notPrimes; i++)
  56.         af << X[i] << endl;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement