#include using namespace std; int main() { int N, M, P, Q; cin >> N >> M >> P >> Q; for(int i=0; i> x >> f; int answer=0; for(int j=1; j<=M; j++) { if((x*j)%P == f) { answer++; } } cout << answer << endl; } }