// naive2 #include #include #include #include using namespace std; typedef long long ll; #define N (1<<24) #define M 100010 int m, n, mx, ax, my, ay, mod, mod2, mod3 = 1<<30; ll x[M], y[M], z[N], a[M], b[M], dp[N]; bool prime[N]; /* ll solve(ll a, ll b){ b *= a; return (amod) return 0; if(dp[a]>=0) return dp[a]; ll res = 0; for(ll i = a; i < mod; i+=a){ res += z[i]; } return dp[a] = res; } int main(){ scanf("%d%d%d%d%d%d%d%d",&m,&n,&mx,&ax,&my,&ay,&mod,&mod2); for(int i = 0; i < m; i++) scanf("%d", x+i); for(int i = 0; i < m; i++) scanf("%d", y+i); for(int i = 0; i < m; i++) z[x[i]] += y[i]; ll xx = x[m-1], yy = y[m-1]; for(int i = m; i < n; i++){ xx = (xx*mx+(ll)ax)&(mod-1); yy = (yy*my+(ll)ay)&(mod-1); z[xx] += yy; } for(int i = 2; i*i 0; j-=i){ z[j/i] += z[j]; } } */ for(int i = 0; i < m; i++) scanf("%d", a+i); for(int i = 0; i < m; i++) scanf("%d", b+i); memset(dp, -1, sizeof(dp)); ll res = 0; for(int i = 0; i < m; i++){ ll r = solve2(a[i])-solve2(a[i]*b[i]); printf("%lld\n", r); (res+=r)&=mod3-1; } ll aa = a[m-1], bb = b[m-1]; for(int i = m; i < n; i++){ aa = ((aa*mx+(ll)ax+mod2-1)&(mod2-1))+1; bb = ((bb*my+(ll)ay+mod2-1)&(mod2-1))+1; (res+=solve2(aa)-solve2(aa*bb))&=mod3-1; } printf("%lld\n", res); return 0; }