【HDOJ】1211 RSA

按照公式推导可求。

 1 #include <stdio.h>
 2 
 3 char power(int a, int b, int n) {
 4     long long val = 1;
 5     int i;
 6     for (i=0; i<b; ++i)
 7         val = (val*a)%n;
 8     return (char)val;
 9 }
10 
11 int main() {
12     int p, q, e, l;
13     int n, d, fn, num, tmp;
14     char ch;
15 
16     while (scanf("%d%d%d%d", &p,&q,&e,&l) != EOF) {
17         while (l--) {
18             scanf("%d", &num);
19             n = p*q;
20             fn = (p-1)*(q-1);
21             d = tmp = 0;
22             while (++d) {
23                 tmp += e;
24                 if (tmp%fn == 1)
25                     break;
26             }
27             ch = power(num, d, n);
28             printf("%c", ch);
29         }
30         printf("\n");
31     }
32 
33     return 0;
34 }

 

posted on 2014-03-21 18:22  Bombe  阅读(141)  评论(0编辑  收藏  举报

导航