给出n和p,求最小的正整数x使得x!>p^q
有斯特林公式n!≈√(2πn)·(n/e)^n
取个log得log(n!)≈0.5*log(2*pi)+(n+0.5)*log(n)-n
然后log(p^q)=q*log(p)
不过二分是过不去的
这个函数可以牛顿迭代,就是对于一个x,在函数上做切线,与x轴的交点作为下一次的x
复杂度是loglogn
eps开到1e-5才能过,低了会WA,高了会TLE
#include<iostream>
#include<cmath>
using namespace std;
typedef long long ll;
int T,p,q,b,c,d,e,f,g;
const int mob=1004535809;
const double pi=acos(-1);
const double __ln_2pi=0.5*log(2*pi);
int main()
{
cin>>T>>p>>q>>b>>c>>d>>e>>f>>g;
ll ans=1;
while(T--)
{
double alpha=q*log(p);
double x=2;
while(1)
{
double __ln_x=log(x);
double temp=__ln_2pi+(x+0.5)*__ln_x-x-alpha;
if(fabs(temp)<1e-5) break;
x-=temp/(__ln_x+0.5/x);
}
(ans*=(ll)ceil(x))%=mob;
p=(ll(p)*b+c)%d+1,q=(ll(q)*e+f)%g+1;
}
cout<<ans<<endl;
return 0;
}