您的位置:首页 > 其它

【BZOJ 3884】 上帝与集合的正确用法|欧拉函数

2016-04-18 17:26 495 查看
开始我感觉题目有问题 。。

后来问了下发现题解说的很对 http://blog.csdn.net/popoqqq/article/details/43951401
快速幂写错耽误一段时间....  搞清幂和指数!注意LL!!!
(LL)(t*t)
这样会爆 T_T














#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define LL long long
int f(int y,int p)
{
if(y==0) return 1%p;
int t=f(y/2,p);
t=(LL)t*t%p;
if(y&1) t=(LL)t*2%p;
return t;
}
int get_phi(int x)
{
int ans=x;
for(int i=2;i*i<=x;i++)
if(x%i==0)
{
ans/=i;
ans*=i-1;
while(x%i==0) x/=i;
}
if(x!=1) ans/=x,ans*=x-1;
return ans;
}
int solve(int p)
{int xxx=p;
if(p==1) return 0;
int tmp=0;
while(p%2==0) p>>=1,tmp++;
int phi=get_phi(p);
int ans=solve(phi);
ans=((ans-tmp)%phi+phi)%phi;
ans=f(ans,p);

return ans<<tmp;
}
int main()
{
int t,x;
cin>>t;
while(t--)
{
cin>>x;
cout<<solve(x)<<endl;
}
}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: