首页 > 代码库 > hdu 1211

hdu 1211

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
典型的快速幂成应用<br>题意:求x 使得x^e%n=num<br>#include<iostream>
using namespace std;
bool funtion(int x,int e,int n,int num)
{// m^n % k
   int b = 1;
    while (e > 0)
    {
          if (e & 1)
             b = (b*x)%n;
          e = e >> 1 ;
          x = (x*x)%n;
    }
    if(b==num) return true;
    return false;
}
int main()
{
    int p,q,e,l,c,n;
    while(scanf("%d%d%d%d",&p,&q,&e,&l)!=EOF)
    {
        n=p*q;
        while(l--)
        {
            scanf("%d",&c);
            for(int i=0;i<=255;i++)
                if(funtion(i,e,n,c))
                {
                    printf("%c",i);
                    break;
                }
        }
        printf("\n");
    }
    return 0;
}