Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- 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 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;
- int kolku_pati = razlika / najgolem_delitel;
- if(razlika % najgolem_delitel > 0) {
- kolku_pati++;
- }
- b -= najgolem_delitel * kolku_pati;
- res += kolku_pati;
- }
- cout << res << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement