Untitled
unknown
plain_text
a year ago
755 B
6
Indexable
#include <iostream>
#include <cmath>
using namespace std;
bool isPrimitiveRoot(int g, int m) {
bool* powers = new bool[m] {false};
for (int i = 1; i < m; i++) {
int power = (int)pow(g, i) % m;
if (powers[power]) {
delete[] powers;
return false;
}
powers[power] = true;
}
delete[] powers;
return true;
}
int main() {
int g, m;
cout << "Enter the number g: ";
cin >> g;
cout << "Enter the modulus m: ";
cin >> m;
if (isPrimitiveRoot(g, m)) {
cout << g << " is a primitive root modulo " << m << endl;
} else {
cout << g << " is not a primitive root modulo " << m << endl;
}
return 0;
}
Editor is loading...
Leave a Comment