题目链接:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2165
For example, if they choose n = 2 and the message is "World" (without quotation marks), they encode the message like this:
1. the first character is 'W', and it's ASCII code is 87. Then f(′W′) = 87^2 mod 997 = 590.
2. the second character is 'o', and it's ASCII code is 111. Then f(′o′) = 111^2 mod 997 = 357.
3. the third character is 'r', and it's ASCII code is 114. Then f(′r′) = 114^2 mod 997 = 35. Since 10 <= f(′r′) < 100, they add a 0 in front and make it 035.
4. the forth character is 'l', and it's ASCII code is 108. Then f(′l′) = 108^2 mod 997 = 697.
5. the fifth character is 'd', and it's ASCII code is 100. Then f(′d′) = 100^2 mod 997 = 30. Since 10 <= f(′d′) < 100, they add a 0 in front and make it 030.
6. Hence, the encrypted message is "590357035697030".
One day, an encrypted message a mathman sent was intercepted by the human being. As the cleverest one, could you find out what the plain text (i.e., the message before encryption) was?
3 2 590357035697030 0 001001001001001 1000000000 001001001001001
World No Solution No Solution 第1行3,代表3组数据,然后每组输入两行 第1行是 n 第2行是要破译的密码; 把密码分成每3个数字1组,去破译 例如第1组样例 590357035697030 把它每3个拆成1组,每组翻译成1个字符,第1行输入的 n=2,代表该字符asc码的几次方 例如 590 = 87^2%997 , 'W的'asc码就是 87,, 所以第1个字母是 W,顺次类推输出了 World; 可以看出只要我们知道了asc码,我们就可以求出 对应的字符,很容易想到打表,由于题目说翻译后的密码只包括大小写字母和数字,数组不用开很大就可以贮存; 而 对求幂取模,,直接套用快速幂模板就好了。 No Solution的情况: 1:没有对应的字符 2:对应的字符多于1个#include <stdio.h> #include <cmath> #include <cstring> #include <stdlib.h> typedef long long ll; const int maxn=1000000+10; char str[maxn]; char test[maxn/3][5]; char ar[1010]; int signaa; ll pow_mod(ll x,ll n, ll mod) //快速幂模板 { ll res=1; x=x%mod; while(n>0) { if(n%2) { res=res*x%mod; } x=x*x%mod; n/=2; } return res; } int main() { int n; scanf("%d",&n); int cas=0; while(n--) { signaa=0; memset(ar,'