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 ...
随机推荐
- Catch That Cow:BFS:加标记数组:不加标记数组
Catch That Cow Problem Description Farmer John has been informed of the location of a fugitive cow a ...
- android入门 — Activity启动模式
1.standard模式 standard模式是系统的默认启动方式,每次激活Activity都会创建Activity,并放在任务栈中. 系统不会在乎活动是否已经存在于返回栈中,每次启动都会创建该活动的 ...
- Alpha-end
前言 失心疯病源10 团队代码管理github 个人感悟 肝不动了,肝不动了.明天如果见不到我,不要太想我. 站立会议 队名:PMS 530雨勤(组长) 今天完成了那些任务 熬夜肝代码 代码签入git ...
- Sql server 中关闭ID自增字段(SQL取消ID自动增长)
sql server在导入数据的时候,有时候要考虑id不变,就要先取消自动增长再导入数据,导完后恢复自增. 比如网站改版从旧数据库导入新数据库,数据库结构不相同,可能会使用insert into xx ...
- css选择器和新增UI样式总结
经过两天的学习,初步对css3选择器和新增UI样式有了进一步的理解.
- phpcms前端模板目录与文件结构分析图【templates】
phpcms前端模板目录与文件结构分析图[templates] 原文地址:http://www.iphpcms.net/phpcms-ziliao/2015_14.html
- c语言----程序记录
1.结构体写入文件,读取 #include <stdio.h> #include <string.h> #include <stdlib.h> #define ma ...
- 新浪 ip 地址库
API地址:http://int.dpool.sina.com.cn/iplookup/iplookup.php 帮助 1 2 3 4 5 6 7 8 function get_location($i ...
- Privoxy
Privoxy 前沿: 这个玩意我以前都没听说过,今天在别人的帮助下试了试,只想说:谁还能阻挡我,我就是要USA....ps:在此感谢每一个帮助我的人 介绍: Privoxy是一款带过滤功能的代理服务 ...
- MySQL专题3 SQL 优化
这两天去京东面试,面试官问了我一个问题,如何优化SQL 我上网查了一下资料,找到了不少方法,做一下记录 (一). 首先使用慢查询分析 通过Mysql 的Slow Query log 可以找到哪些SQ ...