Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <string>
- #include <sstream>
- #include<fstream>
- using namespace std;
- unsigned GCD(unsigned u, unsigned v);
- int main()
- {
- long long int n;
- cout << "Inserisci un numero: ";
- cin >> n;
- if (!n) return 0;
- ofstream savefile("coprime.txt");
- for (int i = 2; i < n; i++)
- {
- if (GCD(i, n) == 1)
- {
- stringstream ss;
- ss << i;
- string str = ss.str();
- savefile << str << endl;
- }
- }
- savefile.close();
- system("PAUSE");
- }
- unsigned GCD(unsigned u, unsigned v) {
- while (v != 0) {
- unsigned r = u % v;
- u = v;
- v = r;
- }
- return u;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement