#define LL "%I64d" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define null NULL #define mp make_pair #define pb(a) push_back(a) #define sz(a) ((int)(a).size()) #define all(a) a.begin() , a.end() #define fi first #define se second #define relaxMin(a , b) (a) = min((a),(b)) #define relaxMax(a , b) (a) = max((a),(b)) #define SQR(a) ((a)*(a)) typedef vector vi; typedef pair pii; typedef long long ll; ll GCD(ll a , ll b){ while(b){ a %= b; swap(a,b); } return a; } ll A , B; int K; ll LO , HI; vector del; int main(){ freopen("game.in" , "r" , stdin); freopen("game.out" , "w" , stdout); scanf(LL LL , &A , &B); A = GCD(A , B); for(ll d=1;d*d <= A;++d){ ll nd = A / d; if(nd * d != A)continue; del.pb(d); if(nd != d)del.pb(nd); } sort(all(del)); scanf("%d" , &K); while(K-- > 0){ scanf(LL LL , &LO , &HI); vector::iterator beg , end; beg = lower_bound(all(del) , LO); end = lower_bound(all(del) , HI+1); int ans = (int)(end - beg); relaxMax(ans , 0); printf("%d\n" , ans); } return 0; }