一种卡精度的方式
查看原帖
一种卡精度的方式
365021
masterhuang楼主2023/10/22 23:34

建议同时学习:https://www.luogu.com.cn/problem/P2293

方法为倍增,相信大家看完代码都能理解:

inline bll ksm(bll x,int p){bll s=1;for(;p;(p&1)&&(s*=x),x*=x,p>>=1);return s;}
inline LL sol(LL n,int x)
{
	if(x==1) return n;
	if(x==2) return sqrtl(n);
	LL t,s=0;for(LL i=1;;i<<=1) if(ksm(i,x)>n){t=i;break;}
	for(t>>=1;t;t>>=1) if(ksm(s+t,x)<=n) s+=t;return s;
}
2023/10/22 23:34
加载中...