Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- void printVec(vector<int> vc) {
- for(int i = 0; i < vc.size(); i++) {
- cout << vc[i] << ' ';
- }
- }
- int getObr(int x, int n) {
- for(int i = 1; i < n; i++) {
- if(i * x % n == 1) {
- return i;
- }
- }
- return 0;
- }
- int main()
- {
- int n;
- cin >> n;
- vector<int> b, x;
- for(int i = 0; i < n; i++) {
- int cur;
- cin >> cur;
- b.push_back(cur);
- }
- for(int i = 0; i < n; i++) {
- int cur;
- cin >> cur;
- x.push_back(cur);
- }
- for(int i = 0; i < n; i++) {
- cout << "B" << i << ": ";
- printVec(b);
- cout << '\n';
- cout << "X" << i << ": ";
- printVec(x);
- cout << '\n';
- int q = x[0];
- int m1 = b[0];
- x.erase(x.begin());
- b.erase(b.begin());
- for(int i = 0; i < x.size(); i++) {
- x[i] = ((((x[i] - q) + b[i]) % b[i]) + b[i]) % b[i];
- }
- cout << "X" << i << " - " << q << ": ";
- printVec(x);
- cout << '\n';
- cout << m1 << "^-1 (mod b) = ";
- for(int i = 0; i < b.size(); i++) {
- cout << getObr(m1, b[i]) << " ";
- }
- cout << '\n';
- for(int i = 0; i < x.size(); i++) {
- x[i] = ((((x[i] * getObr(m1, b[i])) + b[i]) % b[i]) + b[i]) % b[i];
- }
- cout << '\n';
- cout << '\n';
- }
- cout << "End";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement