BZOJ 2219 数论之神 数论

题目大意:求在[0,p)范围内的解的个数

鏼爷的题解:http://jcvb.is-programmer.com/posts/42036

我只是来粘代码的QAQ

指标啥的原根啥的中国剩余定理啥的真的完全不知道QAQ


UPD:时隔多年 在这道题被Hack过一次之后 我终于重新AC了这道题- -

大致说下做法吧


BZOJ 2219 数论之神 数论_第1张图片


感觉说的这么详细不利于深刻理解- -

算了看在这题被Hack得这么惨的份上还是全讲出来吧- -

感谢鏼爷的题解,感谢Mato的数据,感谢wyfcyx丧心病狂地把这组数据加到了OJ上(笑

#include 
#include 
#include 
#include 
#include 
#define INF static_cast(1e15)
#define M 100100
using namespace std;
typedef long long ll;
typedef pair abcd;
namespace Hash_Set{
	ll hash_table[M],val[M],tim[M],T;
	inline void Clear()
	{
		++T;
	}
	ll Hash(ll x,ll v)
	{
		ll i;
		for(i=x%M;tim[i]==T;i++,i%=M)
			if(hash_table[i]==x)
				return val[i];
		tim[i]=T;hash_table[i]=x;
		return val[i]=v;
	}
}
ll Quick_Power(ll x,ll y,ll p)
{
	ll re=1;
	while(y)
	{
		if(y&1) re*=x,re%=p;
		x*=x,x%=p;
		y>>=1;
	}
	return re;
}
ll Get_Primitive_Root(ll p,ll phi_p)
{
	static ll factors[500];
	int i,j,tot=0;
	for(i=2;i*i(ceil(sqrt(C))+1.0000001);
	Hash_Set::Clear();
	for(i=0,A_m=1;i>T;T;T--)
	{
		#ifdef ONLINE_JUDGE
			scanf("%lld%lld%lld",&a,&b,&k);
		#else
			scanf("%I64d%I64d%I64d",&a,&b,&k);
		#endif
	
		k=k<<1|1;ans=1;
		for(i=2; i*i<=k && ans ;i++)
			if(k%i==0)
			{
				ll temp=0;
				while(k%i==0)
					k/=i,++temp;
				ans*=Solve(a,b,i,temp);
			}
		if( ans && k^1 ) ans*=Solve(a,b,k,1);

		#ifdef ONLINE_JUDGE
			printf("%lld\n",ans);
		#else
			printf("%I64d\n",ans);
		#endif
	}
}


你可能感兴趣的:(BZOJ,数论)