Advertisement
Guest User

çaslkdjfaçsldkjf

a guest
Jun 22nd, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.17 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <cmath>
  4. #include <fstream>
  5.  
  6. #define MAX 1000
  7. float rmax = sqrt(MAX);
  8.  
  9. using namespace std;
  10.  
  11. bool primo[MAX];
  12.  
  13. void crivo(void) {
  14.     for(int64_t i = 0; i < MAX; i++) {primo[i] = true;}
  15.     primo[0] = primo[1] = false;
  16.     for(int64_t i = 2; i <= rmax; i++) {
  17.         for(int64_t j = i + i;  j < MAX; j += i) {primo[j] = false;}
  18.     }
  19. }
  20.  
  21. int main(void) {
  22.     ofstream file;
  23.     file.open("resto_primos.txt");
  24.     int i, k, s;
  25.     crivo();
  26.     vector<int64_t> primos;
  27.     vector<int64_t>::iterator it1;
  28.     vector<int64_t>::iterator it2;
  29.     char c;
  30.     for (int64_t i = 0; i < MAX / 2 - 1; i++) {
  31.         if (primo[i]) {
  32.             primos.push_back(i);
  33.         }
  34.     }
  35.     k = 0;
  36.  
  37.    
  38.     for (it1 = primos.begin(); it1 != primos.end(); it1++) file << '\t' << *it1;
  39.     file << '\n';
  40.     file << "---------------------------------------\n";
  41.     for (it1 = primos.begin(); it1 != primos.end(); it1++) {
  42.         file << *it1 << "\t| ";
  43.         for (it2 = primos.begin(); it2 != primos.end(); it2++) {
  44.             file << *it2 % *it1 << '\t';
  45.         }
  46.         file << '\n';
  47.     }
  48.     file.close();
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement