标签:style blog class code width color strong int string set cti
这题就是 要你找出一个ASCII 的值x使得 : x^e%n==num(当前输入的数,e条件已给出)
zsd:
1: ASCII0-255可以枚举
2: =a^11 11=1011
1
2
3
4
5
6
7
8
9
10
11
12 |
int pow2( int
a, int
b ) { int
r = 1, base = a; while ( b != 0 ) { if ( b % 2 ) r *= base; base *= base; //a^x x=1 2 4 8 16 也就是2^x b /= 2; } return
r; } |
3:(x*y)%d=(x%d)*(y%d)
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 |
#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; } |
4:貌似没有用到模线性方程
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 |
#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; } |
标签:style blog class code width color strong int string set cti
原文地址:http://www.cnblogs.com/zhangdashuai/p/3700664.html