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