Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <cmath>
- #include <fstream>
- #define MAX 1000
- float rmax = sqrt(MAX);
- using namespace std;
- bool primo[MAX];
- void crivo(void) {
- for(int64_t i = 0; i < MAX; i++) {primo[i] = true;}
- primo[0] = primo[1] = false;
- for(int64_t i = 2; i <= rmax; i++) {
- for(int64_t j = i + i; j < MAX; j += i) {primo[j] = false;}
- }
- }
- int main(void) {
- ofstream file;
- file.open("resto_primos.txt");
- int i, k, s;
- crivo();
- vector<int64_t> primos;
- vector<int64_t>::iterator it1;
- vector<int64_t>::iterator it2;
- char c;
- for (int64_t i = 0; i < MAX / 2 - 1; i++) {
- if (primo[i]) {
- primos.push_back(i);
- }
- }
- k = 0;
- for (it1 = primos.begin(); it1 != primos.end(); it1++) file << '\t' << *it1;
- file << '\n';
- file << "---------------------------------------\n";
- for (it1 = primos.begin(); it1 != primos.end(); it1++) {
- file << *it1 << "\t| ";
- for (it2 = primos.begin(); it2 != primos.end(); it2++) {
- file << *it2 % *it1 << '\t';
- }
- file << '\n';
- }
- file.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement