题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1211
题意:给你四个数p,q,e,l
n=p*q,f=(p-1)*(q-1)
要你求出一个d满足(e*d)%f=1
然后给你l个c,求出每个c^d%n对应的ASCII。
题解:求d用扩展欧几里得,后面一个用快速幂
AC代码:
#include <iostream>
#include <vector>
#include <list>
#include <deque>
#include <queue>
#include <iterator>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
using namespace std;
typedef long long LL;
const int N=52;
const LL II=29;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
LL p,q,e,l,n,f;
LL love(LL a,LL b,LL c)
{
LL ans=1;
while(b)
{
if(b&1) ans=(ans*a)%c;
a=(a*a)%c;
b=b>>1;
}
return ans;
}
LL ext_gcd(LL a,LL b,LL &x,LL &y)
{
LL t,ret;
if(!b)
{
x=1,y=0;
return a;
}
ret=ext_gcd(b,a%b,x,y);
t=x,x=y,y=t-a/b*y;
return ret;
}
int main()
{
int i,j;
while(~scanf("%I64d%I64d%I64d%I64d",&p,&q,&e,&l))
{
n=p*q;
f=(p-1)*(q-1);
LL d,x,y,c;
d=ext_gcd(e,f,x,y);
d=(x%f+f)%f;
for(LL i=1;i<=l;i++)
{
scanf("%I64d",&c);
x=love(c,d,n);
printf("%c",char(x));
}
puts("");
}
return 0;
}
/*
*/