bzoj3884上帝与集合的正确用法 欧拉定理

一切罪恶的源头
SHOI2017相逢是问候的起源= =
看po姐姐怎么花式虐人,随便想个题让我等蒟蒻跪下膜拜。
http://blog.csdn.net/popoqqq/article/details/43951401

#include<cstdio>
#include<algorithm>
#include<cstring>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
const int N=1e6+5;
int phi[N],pri[N],tot;
typedef long long ll;
bool vis[N];
int p,cnt;
int read()
{
    int x=0,f=1;char ch=getchar();
    while (ch<'0'||ch>'9'){if (ch=='-')f=-1;ch=getchar();}
    while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
inline int Phi(int x)
{
    int i,re=x;
    for(i=2;i*i<=x;i++)
    if (x%i==0)
    {
        re/=i;
        re*=i-1;
        while (x%i==0)x/=i;
    }
    if (x^1)re/=x,re*=x-1;
    return re;
}
inline int pow(ll a,int b,int p)
{
    ll re=1;
    while (b)
    {
        if(b&1)re=re*a%p;
        a=a*a%p;
        b>>=1;
    }
    return re;

}
inline int solve(int p)
{
    if (p==1)return 0;
    int tmp=0;
    while (~p&1)p>>=1,++tmp;
    int phip=Phi(p);
    int re=solve(phip);
    re=(re+phip-tmp%phip)%phip;
    re=pow(2,re,p)%p;
    return re<<tmp;
}
int main()
{
    int cas;
    scanf("%d",&cas);
    while (cas--)
    {
        scanf("%d",&p);
        printf("%d\n",solve(p));
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值