题目链接。
分析:
组队赛时做的这题,不得不说,感慨万千。
因为题目给的是加密文,要求解密,所以就用M = D(c) = cd mod n。 如何d呢,推了推,觉得d是e的乘法逆。结果没过。
后来一商量,觉得ASCII也就那么几个,预处理出来不就完了么?这样,是可以A的,不过在比赛的时候,因为一时疏忽,将一个字母打错(注意是一个字母),一直找BUG。结果没来得及。比赛结束才发现打错了个字母。可恨的是,不论怎么改,样例都过,样例给的真是够“奇妙”的。
#include <cstdio> #include <cstring> #include <cstdlib> #include <algorithm> #include <iostream> #include <cmath> #include <map> using namespace std; typedef unsigned long long LL; LL pow_mod(LL a, LL b, LL n) { if(b == 0) return 1; LL ans = pow_mod(a, b/2, n); ans = (ans*ans)%n; if(b % 2 == 1) ans = (ans * a) % n; return ans; } int main() { LL p, q, e; int l; map<LL, char> a; while(cin >> p >> q >> e >> l) { LL n = p*q; a.clear(); for(int i=0; i<=255; i++) { a[pow_mod(i, e, n)] = (char)i; } LL c; for(int i=0; i<l; i++) { cin >> c; if(a[c] != ' ') cout << a[c]; } putchar('\n'); } return 0; }