Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h>
- #include <string>
- #include <math.h>
- #include <algorithm>
- #include <vector>
- #include <set>
- #include <map>
- #include <sstream>
- #include <queue>
- using namespace std;
- long long NOD(long long a, long long b) {
- long long nod = 1L;
- long long tmp;
- if (a == 0L)
- return b;
- if (b == 0L)
- return a;
- if (a == b)
- return a;
- if (a == 1L || b == 1L)
- return 1L;
- while (a != 0 && b != 0) {
- if (((a & 1L) | (b & 1L)) == 0L) {
- nod <<= 1L;
- a >>= 1L;
- b >>= 1L;
- continue;
- }
- if (((a & 1L) == 0L) && (b & 1L)) {
- a >>= 1L;
- continue;
- }
- if ((a & 1L) && ((b & 1L) == 0L)) {
- b >>= 1L;
- continue;
- }
- if (a > b) {
- tmp = a;
- a = b;
- b = tmp;
- }
- tmp = a;
- a = (b - a) >> 1L;
- b = tmp;
- }
- if (a == 0)
- return nod * b;
- else
- return nod * a;
- }
- int main()
- {
- int n, m;
- cin >> n >> m;
- cout << n-1 + m-1 - NOD(m-1, n-1);
- _getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment