// naive solution #include #include using namespace std; typedef long long ll; #define N (1<<23) int m, n, mx, ax, my, ay, mod, q; ll x[N], y[N], z[N]; bool prime[N]; int main(){ scanf("%d%d%d%d%d%d%d",&m,&n,&mx,&ax,&my,&ay,&mod); assert(1<=m&&m<=100); assert(m<=n&&n<=10000000); assert(1<=mod&&mod<=1<<23); assert(__builtin_popcount(mod)==1); assert(0<=mx&&mx