HDU 3307 Description has only two Sentences


#include <cstdio>
#include <iostream>
using namespace std;
typedef long long LL;
LL gcd(LL a,LL b)
{
    return b==0?a:gcd(b,a%b);
}
LL res[35][2],num;
LL phi(LL x){
    LL ans=x;
    num=0;
    for(LL i=2;i*i<=x;i++)
        if(x%i==0){
        ans=ans/i*(i-1);
        while(x%i==0) x/=i;
        num++;
    }
    if(x>1) ans=ans/x*(x-1);
    return ans;
}
void divide(LL n)
{
    num=0;
    for(LL i=2;i*i<=n;i++)
        if(n%i==0){
            res[num][0]=i;
            res[num][1]=0;
            while(n%i==0) res[num][1]++,n/=i;
            num++;
    }
    if(n>1) res[num][0]=n,res[num++][1]=1;
}
LL X,Y,A;
bool judge(LL a,LL n)
{
    LL r=1;
    while(n)
    {
        if(n&1) r=r*a%A;
        a=a*a%A;
        n>>=1;
    }
    if(r==1) return true;
    return false;
}
int main()
{
    while(~scanf("%I64d%I64d%I64d",&X,&Y,&A)){
        Y/=(X-1);
        A/=gcd(Y,A);
        if(gcd(A,X)!=1)
            printf("Impossible!\n");
        else {
            LL ans=phi(A);
            divide(ans);
            for(int i=0;i<num;i++)
                for(int j=0;j<res[i][1];j++)
                    if(judge(X,ans/res[i][0])) ans/=res[i][0];
            printf("%I64d\n",ans);
        }
    }
    return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值