Advertisement
Pearlfromsu

algorithmic

May 4th, 2023
830
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.94 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <math.h>
  4.  
  5. using namespace std;
  6.  
  7. bool isProst(int n) {
  8.     if(n <= 1)
  9.         return false;
  10.     if(n == 2)
  11.         return true;
  12.     for(int i = 2; i <= sqrt(n); i++)
  13.         if(n%i == 0)
  14.             return false;
  15.     return true;
  16. }
  17.  
  18. int main()
  19. {
  20.     int a, b;
  21.     cin >> a >> b;
  22.     for(int i = a; i <= b; i++)
  23.         if(isProst(i))
  24.             cout << i << ' ';
  25.     return 0;
  26. }
  27.  
  28.  
  29.  
  30. /******************************************************************************
  31.  
  32.                               Online C++ Compiler.
  33.                Code, Compile, Run and Debug C++ program online.
  34. Write your code in this editor and press "Run" button to compile and execute it.
  35.  
  36. *******************************************************************************/
  37.  
  38. #include <iostream>
  39. #include <cmath>
  40. #include <math.h>
  41. #include <vector>
  42. #include <set>
  43.  
  44. using namespace std;
  45.  
  46. int gcd (int a, int b) {
  47.     if (b == 0)
  48.         return a;
  49.     else
  50.         return gcd (b, a % b);
  51. }
  52. int phi (int n) {
  53.     int result = n;
  54.     for (int i=2; i*i<=n; ++i)
  55.         if (n % i == 0) {
  56.             while (n % i == 0)
  57.                 n /= i;
  58.             result -= result / i;
  59.         }
  60.     if (n > 1)
  61.         result -= result / n;
  62.     return result;
  63. }
  64.  
  65. int main()
  66. {
  67.     int n;
  68.     cin >> n;
  69.     cout << "Порядок Z" << n << ": " << phi(n) << '\n' << "Элементы: ";
  70.     vector<int> vc;
  71.     for(int i = 1; i < n; i++)
  72.         if(gcd(i, n) == 1) {
  73.             vc.push_back(i);
  74.             cout << i << ' ';
  75.         }
  76.     cout << '\n';
  77.     for(int i = 0; i < vc.size(); i++) {
  78.         cout << "Элемент " << vc[i] << ": ";
  79.         set<int> st;
  80.         int start = vc[i];
  81.         st.insert(start);
  82.         for(int j = 0; j < 10000; j++) {
  83.             start = (start * vc[i]) % n;
  84.             st.insert(start);
  85.         }
  86.         cout << "("<< st.size() << "):   ";
  87.         for (auto it = st.begin(); it != st.end(); ++it)
  88.             cout << *it << ' ';
  89.         cout << '\n';
  90.     }
  91.  
  92.     return 0;
  93. }
  94.  
  95.  
  96.  
  97.  
  98.  
  99. #include <iostream>
  100. #include <cmath>
  101. #include <math.h>
  102. #include <vector>
  103. #include <set>
  104.  
  105. using namespace std;
  106.  
  107. int main()
  108. {
  109.     //степени a + циклическая группа которую порождает
  110.     int a, n;
  111.     cin >> a >> n;
  112.     int cur = a;
  113.     set<int> st;
  114.     for(int i = 1; i < 300; i++) {
  115.         //cout << a << "^" << i << " = " << cur << "(-" << n - cur <<  ")(mod " << n << ")" << '\n';
  116.         st.insert(cur);
  117.         cur = (cur * a)%n;
  118.     }
  119.    
  120.     cout << "Порождает циклическую подгруппу Z" << n << " порядка " << st.size() << ":" << '\n';
  121.    
  122.     for (auto it = st.begin(); it != st.end(); ++it)
  123.         cout << *it << ' ';
  124.     cout << '\n';
  125.    
  126.     cur = a;
  127.     for(int i = 1; i < 300; i++) {
  128.         cout << a << "^" << i << " = " << cur << "(-" << n - cur <<  ")(mod " << n << ")" << '\n';
  129.         cur = (cur * a)%n;
  130.     }
  131.    
  132.     return 0;
  133. }
  134.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement