Advertisement
Josif_tepe

Untitled

Mar 16th, 2024
476
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5.     ios_base::sync_with_stdio(false);
  6.  
  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 najgolem_delitel = 1;
  15.         int koren = sqrt(a);
  16.  
  17.         for(int i = 2; i <= koren; i++) {
  18.             if(a % i == 0) {
  19.                 najgolem_delitel = a / i;
  20.                 break;
  21.             }
  22.         }
  23.         b -= najgolem_delitel;
  24.         res++;
  25.     }
  26.  
  27.     cout << res << endl;
  28.     return 0;
  29. }
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement