#include using namespace std; const int N = 1e6 + 10; typedef pair PII; PII a[N]; set s; int main() { int n; cin >> n; int x1, ax, bx, cx; int y1, ay, by, cy; cin >> x1 >> ax >> bx >> cx; cin >> y1 >> ay >> by >> cy; // 第一个点进入集合 a[1] = {x1, y1}; s.insert(a[1]); int idx = 1; while (s.size() < n) { int X = (a[idx].first * ax + bx + idx) % cx; int Y = (a[idx].second * ay + by + idx) % cy; a[++idx] = {X, Y}; s.insert(a[idx]); } cout << idx << endl; return 0; }