Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- bool CzyPierwsza(int N) {
- if (N < 2)
- return false;
- if (N == 2)
- return true;
- for (int i = 2; i < N; i++)
- if (N % i == 0)
- return false;
- return true;
- }
- int potega(int a, int x, int M)
- {
- int w = 1;
- int z = a;
- while (x > 0)
- {
- if (x % 2 == 1)
- w = w * z % M;
- z = z * z % M;
- x = x / 2;
- }
- return w;
- }
- int Nwd(int a, int b) {
- while (a != b) {
- if (a < b)
- swap(a, b);
- a -= b;
- }
- return a;
- }
- int main()
- {
- ifstream in;
- in.open("liczby.txt");
- const int liczbaWejsc = 1000;
- int c_1 = 0, c_2 = 0, c_3 = 0;
- for (int i = 0; i < liczbaWejsc; i++) {
- int a, b, M;
- in >> M >> a >> b;
- if (CzyPierwsza(M))
- c_1++;
- if (Nwd(M, a) == 1)
- c_2++;
- bool daSie = false;
- for (int x = 0; x < M; x++) {
- if (potega(a, x, M) == b)
- {
- daSie = true;
- break;
- }
- }
- if (daSie)
- c_3++;
- }
- ofstream out;
- out.open("wyniki3.txt");
- cout << "3.3. " << c_1 << endl;
- cout << "3.4. " << c_2 << endl;
- cout << "3.5. " << c_3 << endl;
- out << "3.3. " << c_1 << endl;
- out << "3.4. " << c_2 << endl;
- out << "3.5. " << c_3 << endl;
- out.flush();
- out.close();
- }
Add Comment
Please, Sign In to add comment