Advertisement
Guest User

Untitled

a guest
Dec 13th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. int main(){
  8.     int a, b;
  9.  
  10.     cout << "Enter a: "; cin >> a;
  11.     cout << "Enter b: "; cin >> b;
  12.  
  13.     vector<int> quotients;
  14.  
  15.     while (b > 0)
  16.     {
  17.         div_t result = div (a,b);
  18.  
  19.         quotients.push_back(result.quot);
  20.         a = b;
  21.         b = result.rem;
  22.     }
  23.  
  24.     int xk [quotients.size() + 1];
  25.     int yk [quotients.size() + 1];
  26.  
  27.     xk[0] = 1;
  28.     xk[1] = 0;
  29.     yk[0] = 0;
  30.     yk[1] = 1;
  31.  
  32.     for (int i = 2; i < quotients.size()  + 1; ++i) {
  33.         xk[i] = quotients[i - 2] * xk[i - 1] + xk[i - 2];
  34.         yk[i] = quotients[i - 2] * yk[i - 1] + yk[i - 2];
  35.     }
  36.  
  37.     cout << xk[quotients.size()] << endl;
  38.     cout << yk[quotients.size()] << endl;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement