Advertisement
Josif_tepe

Untitled

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