Advertisement
Josif_tepe

Untitled

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