Hdu3223 Decrypt Messages
Decrypt Messages
Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 657 Accepted Submission(s): 158
But the time in their contact log has been encrypted, using the following method:
Count the number of seconds from 2000.01.01 00:00:00 to that time, assume this number is x. Then calculate xq, modulo it by a prime number p. The remainder a is the encrypted number.
Your task is to help Leon write a program to decrypt the contact log, and tell him all the possible original time.
1. Remember that if the year can be divided evenly by 4 but can't be divided evenly by 100, or it can be divided evenly by 400, this year is a leap year. The February of a leap year has 29 days, while the February of other years has 28 days.
2. In this problem, if the year modulo 10 is 5 or 8, at the end of this year, there is one “leap second”, i.e., the second after 2005.12.31 23:59:59 is 2005.12.31 23:59:60, and after that second, it's 2006.01.01 00:00:00.
You may assume that from 2000.01.01 00:00:00 till that time, less than p seconds have passed.
The first line of the input contains an integer T, meaning the number of the test cases.
For each test case, a single line of three integers: p, q, and a. (2<p≤1000000007, 1<q≤10, 0≤a<p, p is always a prime.)
If the solution doesn't exist, output Transmission error instead.
See the sample output for further details.
3 2 1
3 2 2
2000.01.01 00:00:01
2000.01.01 00:00:02
Case #2:
Transmission error
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std;
typedef long long ll;
ll p,q,a,g,t;
int T,cas;
vector <ll> yinzi,endd;
map <ll,ll> bsg; ll qpow(ll a,ll b,ll mod)
{
ll res = ;
while(b)
{
if (b & )
res = (res * a) % mod;
a = (a * a) % mod;
b >>= ;
}
return res;
} ll exgcd(ll a,ll b,ll &x,ll &y)
{
if (!b)
{
x = ;
y = ;
return a;
}
ll temp = exgcd(b,a % b,x,y),t = x;
x = y;
y = t - (a / b) * y;
return temp;
} bool check(ll x)
{
ll t = p - ;
for (int i = ; i < yinzi.size(); i++)
if (qpow(x,t / yinzi[i],p) == )
return false;
return true;
} ll getyuangen()
{
ll x = p - ;
yinzi.clear();
for (ll i = ; i <= sqrt(x); i++)
if(x % i == )
{
yinzi.push_back(i);
while(x % i == )
x /= i;
}
if (x != )
yinzi.push_back(x);
ll temp = ;
while(++temp)
if (check(temp))
return temp;
} ll bsgs()
{
bsg.clear();
if (g % p == )
return -;
ll block = ceil(sqrt(p));
ll ans;
for (ll i = ; i <= block; i++)
{
if (i == )
{
ans = a % p;
bsg[ans] = i;
continue;
}
ans = (ans * g) % p;
bsg[ans] = i;
}
ll temp = qpow(g,block,p);
ans = ;
for (ll i = ; i <= block; i++)
{
ans = (ans * temp) % p;
if (bsg[ans])
{
ll anss = i * block - bsg[ans];
return (anss % p + p) % p;
}
}
return -;
} void solve()
{
endd.clear();
ll A = q,B = p - ,C = t,x,y;
ll d = exgcd(A,B,x,y);
if (C % d == )
{
x = (x % B + B) % B;
endd.push_back(x * (C / d) % B);
for (ll i = ; i < d; i++)
endd.push_back((endd[] + i * B / d) % B);
}
} int dd[],hh[],mi[];
int mm[]={,,,,,,,,,,,,};
void print(ll x){
int y,mo,d,h,min,s,i;
for(y=;;y++){
s=***;
if(y%==&&y%||y%==)
s+=**;
if(y%==||y%==)
s++;
if(x-s<)
break;
x-=s;
}
if(y%==&&y%||y%==)
for(i=;i<;i++)
mm[i]+=**;
if(y%==||y%==){
mm[]++;
dd[]++;
hh[]++;
mi[]++;
}
for(i=;i<;i++)
if(x-mm[i]<)
break;
x-=mm[i-];
mo=i;
for(i=;i<;i++)
if(x-dd[i]<)
break;
x-=dd[i-];
d=i;
for(i=;i<;i++)
if(x-hh[i]<)
break;
x-=hh[i-];
h=i-;
for(i=;i<;i++)
if(x-mi[i]<)
break;
x-=mi[i-];
min=i-;
if(y%==&&y%||y%==)
for(i=;i<;i++)
mm[i]-=**;
if(y%==||y%==){
mm[]--;
dd[]--;
hh[]--;
mi[]--;
}
printf("%d.%02d.%02d %02d:%02d:%02lld\n",y,mo,d,h,min,x);
} void init()
{
bsg.clear();
yinzi.clear();
endd.clear();
p = q = a = g = t = ;
} int main()
{
for(int i=;i<;i++)mm[i]=mm[i]***+mm[i-];
for(int i=;i<;i++)dd[i]=i***;
for(int i=;i<;i++)hh[i]=i**;
for(int i=;i<;i++)mi[i]=i*;
scanf("%d",&T);
while(T--)
{
++cas;
init();
scanf("%lld%lld%lld",&p,&q,&a);
printf("Case #%d:\n",cas);
if (a == )
{
printf("2000.01.01 00:00:00\n");
continue;
}
g = getyuangen();
t = bsgs();
if (t == -)
{
printf("Transmission error\n");
continue;
}
solve();
if(endd.size() == )
{
printf("Transmission error\n");
continue;
}
for (int i = ; i < endd.size(); i++)
endd[i] = qpow(g,endd[i],p);
sort(endd.begin(),endd.end());
for (int i = ; i < endd.size(); i++)
print(endd[i]);
} return ;
}
Hdu3223 Decrypt Messages的更多相关文章
- C#/PHP Compatible Encryption (AES256) ZZ
Finding a way to encrypt messages in C# and decrypting them in PHP or vice versa seems to be a " ...
- RSA Encrypting/Decrypting、RSA+AES Encrypting/Decrypting
catalogue . CryptoAPI介绍 . RSA Encrypting/Decrypting File 1. CryptoAPI介绍 0x1: Cryptography Service Pr ...
- sgu 142. Keyword 暴力,hash 难度:0
142. Keyword time limit per test: 0.5 sec. memory limit per test: 16384 KB Kevin has invented a new ...
- SSH secure shell 原理与运用
转: http://www.ruanyifeng.com/blog/2011/12/ssh_remote_login.html 作者: 阮一峰 日期: 2011年12月21日 SSH是每一台Linux ...
- how to extract and decrypt WeChat EnMicromsg.db on Android phone
One of my friend came to me with an Android phone. She saild somehting wrong with the hardware of he ...
- A very simple C++ module to encrypt/decrypt strings based on B64 and Vigenere ciper.
A very simple C++ module to encrypt/decrypt strings based on B64 and Vigenere ciper. https://github. ...
- 微信破解,解密?How To Decrypt WeChat EnMicroMsg.db Database?
20元现金领取地址:http://jdb.jiudingcapital.com/phone.html内部邀请码:C8E245J (不写邀请码,没有现金送) 国内私募机构九鼎控股打造,九鼎投资是在全国股 ...
- Error querying database. Cause: java.lang.IllegalArgumentException:Failed to decrypt.(错误笔记)
java.lang.IllegalArgumentException:Failed to decrypt 从错误可以看出,解密失败. 原因是你在数据库连接配置的地方,设置了加密.即: config.d ...
- Kafka副本管理—— 为何去掉replica.lag.max.messages参数
今天查看Kafka 0.10.0的官方文档,发现了这样一句话:Configuration parameter replica.lag.max.messages was removed. Partiti ...
随机推荐
- MAC下Android的Eclipse开发环境搭建
原文链接:https://www.cnblogs.com/macro-cheng/archive/2011/09/30/android-001.html 一.Eclipse的下载 到网站:http:/ ...
- 排序(C语言实现)
读数据结构与算法分析 插入排序 核心:利用的是从位置0到位置P都是已排序的 所以从位置1开始排序,如果当前位置不对,则和前面元素反复交换重新排序 实现 void InsertionSort(Eleme ...
- scrum立会报告+燃尽图(第三周第一次)
此作业要求参见:https://edu.cnblogs.com/campus/nenu/2018fall/homework/2284 项目地址:https://coding.net/u/wuyy694 ...
- VK Cup 2015 - Round 2 (unofficial online mirror, Div. 1 only) B. Work Group 树形dp
题目链接: http://codeforces.com/problemset/problem/533/B B. Work Group time limit per test2 secondsmemor ...
- 小白用Android MVP-初体验(一)
写android以来,一直都是采用MVC的模式,所有的业务逻辑,网络请求等都放在了View中,即Activity或者Fragment中.看了一些mvp文章,很多跨度较大,也因为自己造诣不够,还不能跟上 ...
- 【week11】psp
本周psp 项目 内容 开始时间 结束时间 被打断 净时间 11.26(星期六) 看论文 psiBlast 9:00 12:00 5 175 11.28(星期一) 做作业 设计模式作业 ...
- 【php】header下载文件后,文件变大的问题;(ob_clean()清空缓存)
事由: 按照常理,为了下载一个生产的文件,都是使用header函数,指定下文件信息,然后开始下载,但是下载后发现,文件体积总是比源文件要大2个字节,源文件是24字节,下载后是26字节,查看服务器返回的 ...
- TDDL调研笔记
一,TDDL是什么 Taobao Distributed Data Layer,即淘宝分布式数据层,简称TDDL .它是一套分布式数据访问引擎 淘宝一个基于客户端的数据库中间件产品 基于JDBC规范, ...
- java 类的强制转型
- iOS pch文件的创建
3.iso pch头文件的创建 输入文件名的时候记得打钩 3.1.在Build Settings 里搜索pref就能找到preflx, 点击设置相对路径 $(SRCROOT) +路径:成功了就会显示 ...