题目http://acm.nyist.net/JudgeOnline/problem.php?pid=881
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
vector<int>v;
int main(){
int a,b;
while(scanf("%d%d",&a,&b)!=EOF){//保证可以输入多组数据,否则会WA
v.clear();
int t=(a>b?b:a);
for(int i=1;i<=t;i++){
if((a%i==0)&&(b%i==0)){
v.push_back(i);
}
}
int n,l,r;
scanf("%d",&n);
while(n--){
scanf("%d%d",&l,&r);
int i;
for(i=v.size()-1;i>=0;i--){
if((v[i]>=l)&&(v[i]<=r)){
printf("%d\n",v[i]);
break;
}
}
if(i==-1){
printf("-1\n");
}
}
}
return 0;
}