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

开始我感觉题目有问题 。。

后来问了下发现题解说的很对 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;
	}
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值