Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <algorithm>
- using namespace std;
- int Evklid(int a, int b)
- {
- int res=1;
- while (a!=0 && b!=0)
- {
- while (a%2==0 && b%2==0)
- {
- a/=2;
- b/=2;
- res*=2;
- }
- while (a%2==0)
- a/=2;
- while (b%2==0)
- b/=2;
- if (a>=b) a-=b;
- else b-=a;
- }
- return res*b;
- }
- int main()
- {
- int a=0, b=0;
- cin >> a >> b;
- cout << Evklid(a, b);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement