#include #include #include using namespace std; using ll=long long; using ui=unsigned; const ll MOD=100000009; struct en_t { int c[3]; en_t operator+(const en_t& rhs) { return (en_t){c[0]+rhs.c[0], c[1]+rhs.c[1], c[2]+rhs.c[2]}; } int cmp(const en_t& rhs) { if(c[0]==rhs.c[0] && c[1]==rhs.c[1] && c[2]==rhs.c[2]) return 0; if(c[0]<=rhs.c[0] && c[1]<=rhs.c[1] && c[2]<=rhs.c[2]) return -1; if(c[0]>=rhs.c[0] && c[1]>=rhs.c[1] && c[2]>=rhs.c[2]) return 1; return 2; } }; int calc(ll x, int b) { int i; for(i=0;x%b==0;i++) x/=b; return i; } int min(int a, int b) { if(av) { m=v; return 1; } return 0; } int solve(int seed, int n, int k, int b) { vector x(n+1); vector c(n+1); vector e, rm; vector > dp; en_t en={{0,0,0}}, tc; int t, is_need_add, ret=999999; dp.resize(k+1); dp[0].push_back(en); t=b; for(int i=2;i<=t;i++) { int j; for(j=0;t%i==0;j++) { t/=i; } if(j) { en.c[e.size()]=j; e.push_back(i); } } x[0]=seed; for(int i=1;i<=n;i++) { x[i]=1+(x[i-1]*x[i-1]+x[i-1]*12345)%MOD; } for(int i=0;i<=n;i++) { for(ui j=0;j=0;j--) { for(ui k=0;k