shu 423 密码破解

题目链接点这里


#include<bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3f
#define FIN freopen("input.txt","r",stdin)
#define mem(x,y) memset(x,y,sizeof(x))
typedef unsigned long long ULL;
typedef long long LL;
#define fuck(x) cout<<"["<<x<<"]"<<endl;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
typedef pair<pair<int,int>,int> PIII;
typedef pair<int,int> PII;
const double eps=1e-6;
const int MX=1e2+5;
LL P;
LL e,p,q,n;
LL exgcd(LL a,LL b,LL &x,LL &y)
{
    if(b==0)
    {
        x=1,y=0;
        return a;
    }
    LL d=exgcd(b,a%b,y,x);
    y-=a/b*x;
    return d;
}
//ax+by=c
LL solve(LL a,LL b,LL c,LL &x,LL &y)
{
    LL d;
    if(c%(d=__gcd(a,b)))return -1;//返回-1是无解
    a/=d;
    b/=d;
    c/=d;
    exgcd(a,b,x,y);
    x=((LL)x*c)%b;
    while(x<=0)x+=b;
}
LL w[MX];
LL multi(LL a,LL b)
{
    LL ans=0;
    while(b)
    {
        if(b&1)ans=(ans+a)%P;
        a=(a+a)%P;
        b>>=1;
    }
    return ans;
}
LL quick_pow(LL a,LL x)
{
    LL ans=1;
    while(x)
    {
        if(x&1)ans=multi(ans,a);
        a=multi(a,a);
        x>>=1;
    }
    return ans;
}
int main()
{
    FIN;
    int t;
    cin>>t;
    while(t--)
    {
        cin>>e>>p>>q>>n;
        P=p*q;
        LL x,y;
        solve(e,(p-1)*(q-1),1,x,y);
        for(int i=1; i<=n; i++)cin>>w[i];
        for(int i=1; i<=n; i++)
        {
            w[i]=quick_pow(w[i],x);
            printf("%lld%c",w[i],((i==n)?'\n':' '));
        }
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值