#include using namespace std; using Int=long long; using Real=long double; templateinline bool chmin(T&A,S B){if(A>B){A=B;return true;}else{return false;}} templateinline bool chmax(T&A,S B){if(A>seed>>N>>K>>B; X[0]=seed; REP1(i,N)X[i]=1+(X[i-1]*X[i-1]+X[i-1]*12345)%100000009; vectorpB; for(int i=2;i*i<=B;++i) { while(B%i==0) { B/=i; pB.push_back(i); } } if(B>1)pB.push_back(B); for(int p:pB)++cnt[p]; pB.erase(unique(ALL(pB)),end(pB)); int ans=1e9; for(int p:pB) { REP(i,N+1) { A[i]=0; while(X[i]%p==0) { X[i]/=p; ++A[i]; } } sort(A,A+N+1); chmin(ans,accumulate(A,A+K,0)/cnt[p]); } cout<>T; while(T--)sol(); }