BZOJ3884 LuoguP4139 上帝与集合的正确用法
2018-02-02 23:28
197 查看
扩展欧拉定理:a的b次方同余于a的b%phi(p)次方 (mod p) (gcd(a,p)=1)
http://blog.csdn.net/ez_yww/article/details/76176970
题解地址
http://blog.csdn.net/popoqqq/article/details/43951401
http://blog.csdn.net/ez_yww/article/details/76176970
题解地址
http://blog.csdn.net/popoqqq/article/details/43951401
#include<iostream> #include<cstring> #include<cstdio> #include<algorithm> #include<string> #include<cmath> #include<vector> #include<queue> #include<cstdlib> #include<ctime> typedef long long ll; using namespace std; int T,p; inline int phi(int x)//E(x)=x*(1-1/p1)*(1-1/p2)*(1-1/p3)*(1-1/p4)…(1-1/pn),其中p1,p2……pn为x的所有素因数,x是不为0的整数。E(1)=1(唯一和1互质的数就是1本身) { int ans=x,now=x; for(int i=2;i*i<=now;i++) { if(now%i==0) { ans=ans/i*(i-1); while(now%i==0)now/=i; } } if(now>1)//最后只剩下 小于4的素数 或者n本身就是素数 { ans=ans/now*(now-1); } return ans; } inline int ksm(ll a,int b,int M) { ll ans=1; while(b) { if(b&1)ans=(ans*a)%M; a=(a*a)%M; b>>=1; } return ans; } inline int solve(int p) { if(p==1)return 0; int tmp=0; while(!(p&1)){ tmp++;p>>=1; } int phi_p=phi(p); int ans=solve(phi_p); ans=(ans-tmp%phi_p+phi_p)%phi_p; ans=ksm(2,ans,p)%p; return ans<<tmp; } int main() { cin>>T; while(T--) { cin>>p; cout<<solve(p)<<endl; } return 0; }
相关文章推荐
- [BZOJ 3884][欧拉定理]上帝与集合的正确用法
- BZOJ 3884: 上帝与集合的正确用法|数论
- 【数学】[BZOJ 3884] 上帝与集合的正确用法
- BZOJ 3884 上帝与集合的正确用法 (欧拉函数 找递推公式)
- 【bzoj3884】上帝与集合的正确用法 扩展欧拉定理
- 【BZOJ 3884】上帝与集合的正确用法【欧拉降幂】
- 【BZOJ 3884】上帝与集合的正确用法
- 【BZOJ 3884】 上帝与集合的正确用法|欧拉函数
- bzoj千题计划264:bzoj3884: 上帝与集合的正确用法
- BZOJ 3884 上帝与集合的正确用法
- 【bzoj3884】【上帝与集合的正确用法】【数论】
- bzoj 3884: 上帝与集合的正确用法(欧拉函数)
- BZOJ 3884 上帝与集合的正确用法
- (bzoj 3884 上帝与集合的正确用法)<欧拉定理>
- bzoj 3884: 上帝与集合的正确用法
- 【BZOJ3884】【欧拉函数】上帝与集合的正确用法 题解
- BZOJ 3884 上帝与集合的正确用法
- 【BZOJ 3884】【欧拉定理或者求幂大法】上帝与集合的正确用法
- bzoj 3884: 上帝与集合的正确用法
- [BZOJ 3884] 上帝与集合的正确用法 欧拉定理