1 #include <cstdio>
2 #include <cstring>
3 #include <iostream>
4 #include <algorithm>
5 #include <cmath>
6 #include <vector>
7 #include <set>
8 #include <map>
9 #include <time.h>
10 using namespace std;
11
12 typedef long long ll;
13
14 vector<int> x;
15 int L, R, A, B, N, m, ans;
16
17 int main()
18 {
19 // freopen("in.txt", "r", stdin);
20 // freopen("out.txt", "w", stdout);
21
22 while(scanf("%d%d", &A, &B) == 2) {
23 A = __gcd(A, B);
24 B = sqrt(A);
25 x.clear();
26 for (int i = 1;i <= B;i++)
27 if (A%i == 0) {
28 x.push_back(i);
29 x.push_back(A/i);
30 }
31
32 sort(x.begin(), x.end());
33
34 scanf("%d", &N);
35 //printf("%d! ", N);
36 for (int i = 0;i < N;i++) {
37 scanf("%d%d", &L, &R);
38 m = upper_bound(x.begin(), x.end(), R) - x.begin() - 1;
39 ans = x[m];
40 if (L > ans) puts("0");
41 else printf("%d ", ans);
42 //if(i > 9600) printf("%d ", i);
43 }
44 printf(" ");
45 }
46 return 0;
47
48 }
2 #include <cstring>
3 #include <iostream>
4 #include <algorithm>
5 #include <cmath>
6 #include <vector>
7 #include <set>
8 #include <map>
9 #include <time.h>
10 using namespace std;
11
12 typedef long long ll;
13
14 vector<int> x;
15 int L, R, A, B, N, m, ans;
16
17 int main()
18 {
19 // freopen("in.txt", "r", stdin);
20 // freopen("out.txt", "w", stdout);
21
22 while(scanf("%d%d", &A, &B) == 2) {
23 A = __gcd(A, B);
24 B = sqrt(A);
25 x.clear();
26 for (int i = 1;i <= B;i++)
27 if (A%i == 0) {
28 x.push_back(i);
29 x.push_back(A/i);
30 }
31
32 sort(x.begin(), x.end());
33
34 scanf("%d", &N);
35 //printf("%d! ", N);
36 for (int i = 0;i < N;i++) {
37 scanf("%d%d", &L, &R);
38 m = upper_bound(x.begin(), x.end(), R) - x.begin() - 1;
39 ans = x[m];
40 if (L > ans) puts("0");
41 else printf("%d ", ans);
42 //if(i > 9600) printf("%d ", i);
43 }
44 printf(" ");
45 }
46 return 0;
47
48 }