Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int* fillRing(int n) {
- int* ring = new int[n];
- for(int i = 0; i < n; i++) {
- ring[i] = i;
- }
- return ring;
- }
- int add(int left, int right, int n) {
- if(left > n || right > n) {
- return -1;
- }
- return (left + right) % n;
- }
- int subract(int left, int right, int n) {
- if(left > n || right > n) {
- return -1;
- }
- int res = left - right;
- if(res < 0) {
- res = n + res;
- }
- return res;
- }
- int multiply(int left, int right, int n) {
- if(left > n || right > n) {
- return -1;
- }
- return (left * right) % n;
- }
- int** fillPairs(int n) {
- int** result = new int*[2];
- result[0] = new int[n];
- result[1] = new int[n];
- int c = 0;
- for(int i = 1; i < n; i++) {
- for(int j = 1; j < n; j++) {
- unsigned int mult = j*i;
- if((mult % n) == 1) {
- result[0][c] = i;
- result[1][c] = j;
- c++;
- }
- }
- }
- result[0][c] = -1; // Last element;
- result[1][c] = -1; // Last element;
- return result;
- }
- int main() {
- int n = 7;
- int* ring = fillRing(n);
- cout << add(0, 4, n) << endl;
- cout << add(3, 4, n) << endl;
- cout << add(2, 6, n) << endl;
- cout << add(4, 5, n) << endl;
- cout << subract(2, 5, n) << endl;
- cout << subract(1, 3, n) << endl;
- cout << subract(4, 5, n) << endl;
- cout << multiply(2, 6, n) << endl;
- cout << multiply(4, 4, n) << endl;
- cout << multiply(5, 5, n) << endl;
- int **pairs = fillPairs(n);
- int i = 0;
- while(pairs[0][i] != -1) {
- cout << pairs[0][i] << " * " << pairs[1][i] << " % " << n << " = 1" << endl;
- i++;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement