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 koren = sqrt(a);
- int najgolem_delitel = 1;
- 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 -= kolku_pati * najgolem_delitel;
- res += kolku_pati;
- }
- cout << res << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement