Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<algorithm>
- #include<set>
- #include<vector>
- #include<string>
- #include<stdlib.h>
- #include<math.h>
- #include<stdio.h>
- #include<map>
- #include<iostream>
- using namespace std;
- set<long long> s;
- int main()
- {
- long long a, b;
- cin >> a >> b;
- long long x = max(a, b);
- long long y = min(a, b);
- for (long long i = 1; i*i <= x; i++)
- {
- if ((x%i == 0)&&(y%i==0))
- {
- s.insert(i);
- }
- if ((y % (x / i) == 0)&&(x%i==0))
- {
- s.insert(x / i);
- }
- }
- long long jmin, jmax;
- long long e = -1;
- long long k;
- cin >> k;
- for (int i = 0; i < k; i++)
- {
- cin >> jmin >> jmax;
- auto it = s.end();
- it--;
- while (*it > jmax)
- {
- it--;
- }
- if ((*it >= jmin) && (*it <= jmax))
- {
- e = *it;
- }
- cout << e << endl;
- e = -1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement