Advertisement
Pearlfromsu

determine the sign of the number represented relative to the base vector by a standard set of residu

Dec 12th, 2024
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.36 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5.  
  6. void printVec(vector<int> vc) {
  7.   for(int i = 0; i < vc.size(); i++) {
  8.     cout << vc[i] << ' ';
  9.   }
  10. }
  11.  
  12. int getObr(int x, int n) {
  13.   for(int i = 1; i < n; i++) {
  14.     if(i * x % n == 1) {
  15.       return i;
  16.     }
  17.   }
  18.   return 0;
  19. }
  20.  
  21. int main()
  22. {
  23.   int n;
  24.   cin >> n;
  25.   vector<int> b, x;
  26.   for(int i = 0; i < n; i++) {
  27.     int cur;
  28.     cin >> cur;
  29.     b.push_back(cur);
  30.   }
  31.  
  32.   for(int i = 0; i < n; i++) {
  33.     int cur;
  34.     cin >> cur;
  35.     x.push_back(cur);
  36.   }
  37.  
  38.  
  39.   for(int i = 0; i < n; i++) {
  40.     cout << "B" << i << ": ";
  41.     printVec(b);
  42.     cout << '\n';
  43.     cout << "X" << i << ": ";
  44.     printVec(x);
  45.     cout << '\n';
  46.    
  47.     int q = x[0];
  48.     int m1 = b[0];
  49.     x.erase(x.begin());
  50.     b.erase(b.begin());
  51.     for(int i = 0; i < x.size(); i++) {
  52.       x[i] = ((((x[i] - q) + b[i]) % b[i]) + b[i]) % b[i];
  53.     }
  54.    
  55.     cout << "X" << i << " - " << q << ": ";
  56.     printVec(x);
  57.     cout << '\n';
  58.    
  59.     cout << m1 << "^-1 (mod b) = ";
  60.     for(int i = 0; i < b.size(); i++) {
  61.         cout << getObr(m1, b[i]) << " ";
  62.     }
  63.    
  64.     cout << '\n';
  65.    
  66.     for(int i = 0; i < x.size(); i++) {
  67.       x[i] = ((((x[i] * getObr(m1, b[i])) + b[i]) % b[i]) + b[i]) % b[i];
  68.     }
  69.     cout << '\n';
  70.     cout << '\n';
  71.   }
  72.     cout << "End";
  73.     return 0;
  74. }
  75.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement