hdu 1211

时间:2014-04-29 20:20:25   收藏:0   阅读:414
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;
}

 

hdu 1211,码迷,mamicode.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!