Advertisement
Josif_tepe

Untitled

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