#include #include #include using namespace std; typedef long long ll; #define N (1<<24) #define M 100 int m, n, mx, ax, my, ay, mod, mod2, mod3 = 1e9+7; ll x[M], y[M], z[N], a[M], b[M]; bool prime[N]; ll solve(ll a, ll b){ b *= a; return (a 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); ll res = 0; for(int i = 0; i < m; i++){ ll r = solve(a[i], b[i]); printf("%lld\n", r); (res+=r)%=mod3; } 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+=solve(aa, bb))%=mod3; } printf("%lld\n", res); }