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

事实这就是个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[n]=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;
}



  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值