Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- int main() {
- ios_base::sync_with_stdio(false);
- int a, b;
- cin >> a >> b;
- int res = 0;
- while(a != b) {
- if(a > b) {
- swap(a, b);
- }
- int sq = sqrt(a);
- int max_divisor = 1;
- for(int i = 2; i <= sq; i++) {
- if(a % i == 0) {
- max_divisor = a / i;
- break;
- }
- }
- int diff = b - a;
- int tmp = diff / max_divisor;
- if(diff % max_divisor != 0) {
- tmp++;
- }
- b -= tmp * max_divisor;
- res += tmp;
- }
- cout << res << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement