您的位置:首页 > 其它

UOJ #74. 【UR #6】破解密码

2016-07-07 21:37 351 查看
事实这就是个hash

然后告诉你 hash值 求原字符串

注意h[i] 与 h[i+1]直接的关系

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int MAXN = 1e5+10;
#define LL long long
char out[MAXN];
int n,p,h[MAXN];
int power(int x,int y)
{
if(y==0) return 1;
int t=power(x,y/2);
t=(LL)t*t%p;
if(y&1) t=(LL)t*x%p;
return t;
}
int main()
{
cin >>n >>p;
for(int i=0;i<n;i++) scanf("%d",&h[i]);//cout<<"fd"<<endl;
int opt=(power(26,n)-1)%p;
h
=h[0];//cout<<opt<<endl;
if(opt!=0)
{//cout<<"faf";
for(int j=0;j<n;j++)
for(int i=0;i<26;i++)
if(h[j+1]==(((LL)h[j]*26-(LL)opt*i)%p+p)%p)
{
out[j]='a'+i;
break;
}
puts(out);//cout<<"fa";
}
else
{

for(int i=n-1;i>=0;i--)
{
out[i]=h[0]%26+'a';
h[0]/=26;
}
puts(out);
}
return 0;
}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: