一道很神奇的数论题
利用欧拉定理随便搞搞
不会打题面给的222……很不爽啊
还是一起Orz PoPoQQQ的题解吧
http://blog.csdn.net/popoqqq/article/details/43951401
#include<set>
#include<map>
#include<ctime>
#include<queue>
#include<cmath>
#include<cstdio>
#include<vector>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
int sc()
{
int i=0; char c=getchar();
while(c>'9'||c<'0')c=getchar();
while(c>='0'&&c<='9')i=i*10+c-'0',c=getchar();
return i;
}
int __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 cal(long long x,int y,int p)
{
long long ans=1;
while(y)
{
if(y&1)ans=(x*ans)%p;
y>>=1;
x=x*x%p;
}
//cout << p <<" " << ans <<endl;
return ans;
}
int solve(int p)
{
if(p==1)return 0;
int temp=0;
while((p&1)==0)p>>=1,temp++;
int phi=__phi(p);
int ans=solve(phi);
ans=(ans+phi-temp%phi)%phi;
ans=cal(2,ans,p)%p;
return ans<<temp;
}
int main()
{
int T=sc();
while(T--)
{
long long x=sc();
printf("%d\n",solve(x));
}
return 0;
}