Guest User

Untitled

a guest
Jul 16th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. int zapulvane(int *arr, unsigned n) {
  4. for (unsigned i = 0; i < n; i++) {
  5. arr[i] = i;
  6. }
  7. return 0;
  8. }
  9.  
  10. int subirane(int a, int b, unsigned n) {
  11. return (a + b) % n;
  12. }
  13.  
  14. int izvajdane(int a, int b, unsigned n)
  15. {
  16. int sum = 0;
  17. sum = a - b;
  18. if (sum<0) {
  19. sum = abs(sum);
  20. return n - sum;
  21. }
  22. else return sum % n;
  23. }
  24.  
  25. int umnojenie(int a, int b, unsigned n) {
  26. return (a*b) % n;
  27. }
  28.  
  29. int recelem(unsigned n, int elem) {
  30. for (unsigned i = 0; i<n; i++)
  31. {
  32. if (umnojenie(i, elem, n) == 1) {
  33. return i;
  34. break;
  35. }
  36. }
  37. return 0;
  38. }
  39.  
  40. int delenie(int a, int b, unsigned n) {
  41. if (recelem(n, b) > 0) {
  42. return umnojenie(a, recelem(n, b), n);
  43. }
  44. else {
  45. return -1;
  46. }
  47. }
  48.  
  49. int reciprochen(int **arr, unsigned cn) {
  50. int t = 0;
  51. for (unsigned j = 0; j<cn; j++)
  52. {
  53. t = arr[1][j];
  54. arr[1][j] = arr[0][j];
  55. arr[0][j] = t;
  56. }
  57. for (unsigned i = 0; i<2; i++)
  58. {
  59. for (unsigned j = 0; j<cn; j++)
  60. {
  61. std::cout << " " << arr[i][j];
  62. }
  63. std::cout << std::endl;
  64. }
  65. return 0;
  66. }
  67.  
  68. int dvoiki(unsigned n)
  69. {
  70. unsigned cn = 0;
  71. for (unsigned i = 0; i<n; i++)
  72. {
  73. for (unsigned j = i; j<n; j++)
  74. {
  75. if (umnojenie(i, j, n) == 1) {
  76. cn++;
  77. }
  78. }
  79. }
  80. int **ar = NULL;
  81. ar = new int*[2];
  82. for (unsigned i = 0; i<2; i++)
  83. {
  84. ar[i] = new int[cn];
  85. }
  86. cn = 0;
  87. for (unsigned i = 0; i<n; i++)
  88. {
  89. for (unsigned j = i; j<n; j++)
  90. {
  91. if (umnojenie(i, j, n) == 1)
  92. {
  93.  
  94. ar[0][cn] = i;
  95. ar[1][cn] = j;
  96. cn++;
  97. }
  98. }
  99. }
  100. for (unsigned i = 0; i<2; i++)
  101. {
  102. for (unsigned j = 0; j<cn; j++)
  103. {
  104. std::cout << " " << ar[i][j];
  105. }
  106. std::cout << std::endl;
  107. }
  108. std::cout << std::endl;
  109. reciprochen(ar, cn);
  110. for (unsigned i = 0; i < 2; i++) {
  111. delete[] ar[i];
  112. }
  113. delete[] ar;
  114. ar = NULL;
  115. return 0;
  116. }
  117.  
  118. int stepenuvane(unsigned n, int a, int m) {
  119. int c = a, cnt = 2;
  120. do {
  121. cnt++;
  122. c = umnojenie(a, c, n);
  123. } while (umnojenie(a, c, n) != 1);
  124. return umnojenie(a, cnt, n);
  125. }
  126.  
  127. int primitiven(int a, unsigned n) {
  128. int *ar = NULL, b;
  129. ar = new int[n];
  130. bool c = true;
  131. for (unsigned i = 1; i < n; i++) {
  132. b = pow(a, i);
  133. ar[i] = b % n;
  134. }
  135. for (unsigned i = 1; i < n; i++) {
  136. for (unsigned j = i + 1; j < n; j++) {
  137. if (ar[i] == ar[j]) {
  138. c = false;
  139. break;
  140. }
  141. }
  142. }
  143. if (c == true) {
  144. std::cout << "Chisloto e primitiven koren" << std::endl;
  145. }
  146. if (c == false) {
  147. std::cout << "Chisloto NE e primitiven koren" << std::endl;
  148. }
  149. return 0;
  150. }
Add Comment
Please, Sign In to add comment