#include #include #include using namespace std; typedef long long ll; const int INF = 1 << 25; const int MOD = 100000009; vector gen(int seed, int N){ vector x(N + 1); x[0] = seed; for(int n=1;n<=N;n++){ ll pre = x[n-1]; x[n] = 1 + (pre * pre % MOD + pre * 12345ll % MOD) % MOD; } return x; } vector< pair > getFactors(int n){ vector< pair > res; for(int p=2;p*p<=n;p++)if(n % p == 0){ int e = 0; while(n % p == 0){ ++e; n /= p; } res.push_back(make_pair(p, e)); } if(n != 1){ res.push_back(make_pair(n, 1)); } return res; } int solve(int seed, int N, int K, int B){ vector x = gen(seed, N); vector< pair > factors = getFactors(B); int res = INF; for(int i=0;i y = x; for(int j=0;j> Q; for(int i=0;i> seed; cin >> N; cin >> K; cin >> B; cout << solve(seed, N, K, B) << endl; } return 0; }