Advertisement
Josif_tepe

Untitled

Mar 15th, 2024
594
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.69 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4. int main() {
  5.     ios_base::sync_with_stdio(false);
  6.     int a, b;
  7.     cin >> a >> b;
  8.     int res = 0;
  9.     while(a != b) {
  10.        
  11.         if(a > b) {
  12.             swap(a, b);
  13.         }
  14.         int sq = sqrt(a);
  15.         int max_divisor = 1;
  16.         for(int i = 2; i <= sq; i++) {
  17.             if(a % i == 0) {
  18.                 max_divisor = a / i;
  19.                 break;
  20.             }
  21.         }
  22.         int diff = b - a;
  23.         int tmp = diff / max_divisor;
  24.         if(diff % max_divisor != 0) {
  25.             tmp++;
  26.         }
  27.         b -= tmp * max_divisor;
  28.         res += tmp;
  29.     }
  30.     cout << res << endl;
  31.     return 0;
  32. }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement