Advertisement
Josif_tepe

Untitled

Mar 15th, 2024
444
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. int main() {
  5.     int a, b;
  6.     cin >> a >> b;
  7.    
  8.     int brojac = 0;
  9.     while(a != b) {
  10.         if(a > b) {
  11.             swap(a, b);
  12.         }
  13.        
  14.         int sq = sqrt(a);
  15.         int najgolem_delitel = 1;
  16.         for(int i = 2; i <= sq; i++) {
  17.             if(a % i == 0) {
  18.                 najgolem_delitel = a / i;
  19.                 break;
  20.             }
  21.         }
  22.         int razlika = b - a;
  23.         razlika /= najgolem_delitel;
  24.         if((b - a) % najgolem_delitel != 0) {
  25.             razlika++;
  26.         }
  27.         b -= razlika * najgolem_delitel;
  28.        
  29.         brojac += razlika;
  30.     }
  31.    
  32.     cout << brojac << endl;
  33.     return 0;
  34. }
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement