BZOJ3239 Discrete Logging
一道裸的BSGS题目(叫baby step, giant step)
从爱酱的blog里学来的,是一个很神的根号算法。
如果我们有hash的工具的话,就是O(sqrt(p))的,这里又用了一个map所以是O(sqrt(p) * log(sqrt(p)))
/**************************************************************
Problem: 3239
User: rausen
Language: C++
Result: Accepted
Time:280 ms
Memory:2932 kb
****************************************************************/ #include <cstdio>
#include <cmath>
#include <map> using namespace std;
typedef long long ll; ll p, y, z, B;
map <ll, int> mp; ll pow(ll a, ll x) {
a %= p;
ll res = , base = a;
while (x) {
if (x & ) (res *= base) %= p;
(base *= base) %= p;
x >>= ;
}
return res;
} int main() {
ll i, now, base, tmp;
while (scanf("%lld%lld%lld", &p, &y, &z) != EOF) {
mp.clear();
y %= p;
if (!y) {
if (!z) puts("");
else puts("no solution");
goto end_of_work;
}
B = (int) ceil(sqrt(p)), now = ;
mp[] = B + ;
for (i = ; i < B; ++i) {
(now *= y) %= p;
if (!mp[now]) mp[now] = i;
}
now = , base = pow(y, p - B - );
for (i = ; i < B; ++i) {
tmp = mp[z * now % p];
if (tmp) {
if (tmp == B + ) tmp = ;
printf("%lld\n", i * B + tmp);
goto end_of_work;
}
(now *= base) %= p;
}
puts("no solution");
end_of_work:;
}
return ;
}
(p.s. bz上开了O2,所以还不是很慢恩!)
BZOJ3239 Discrete Logging的更多相关文章
- 【BSGS】BZOJ3239 Discrete Logging
3239: Discrete Logging Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 729 Solved: 485[Submit][Statu ...
- 【BZOJ3239】Discrete Logging BSGS
[BZOJ3239]Discrete Logging Description Given a prime P, 2 <= P < 231, an integer B, 2 <= B ...
- poj 2417 Discrete Logging ---高次同余第一种类型。babystep_gaint_step
Discrete Logging Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 2831 Accepted: 1391 ...
- BSGS算法+逆元 POJ 2417 Discrete Logging
POJ 2417 Discrete Logging Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 4860 Accept ...
- POJ 2417 Discrete Logging (Baby-Step Giant-Step)
Discrete Logging Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 2819 Accepted: 1386 ...
- POJ2417 Discrete Logging【BSGS】
Discrete Logging Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 5577 Accepted: 2494 ...
- [POJ2417]Discrete Logging(指数级同余方程)
Discrete Logging Given a prime P, 2 <= P < 2 31, an integer B, 2 <= B < P, and an intege ...
- Discrete Logging
Discrete Logging Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 5865 Accepted: 2618 ...
- BSGS 扩展大步小步法解决离散对数问题 (BZOJ 3239: Discrete Logging// 2480: Spoj3105 Mod)
我先转为敬? orz% miskcoo 贴板子 BZOJ 3239: Discrete Logging//2480: Spoj3105 Mod(两道题输入不同,我这里只贴了3239的代码) CODE ...
随机推荐
- SUBSTRING_INDEX()
http://dev.mysql.com/doc/refman/5.7/en/string-functions.html#function_substring-index ) DEFAULT 'fru ...
- 【手机自动化测试】monkey测试
1 概述 Monkey测试是Android自动化测试的一种手段.Monkey测试本身非常简单,就是模拟用户的按键输入,触摸屏输入,手势输入等,看设备多长时间会出异常. 当Mon ...
- (1.3)DML增强功能-Apply、pivot、unpivot、for xml path行列转换
深入了解行列转换请参考另一篇文章:https://www.cnblogs.com/gered/p/9271581.html 总结: 1.apply一般形式 --基本形式 SELECT a FROM d ...
- hbase Java API 介绍及使用示例
几个相关类与HBase数据模型之间的对应关系 java类 HBase数据模型 HBaseAdmin 数据库(DataBase) HBaseConfiguration HTable 表(Table) ...
- 《大话设计模式》ruby版代码:外观模式
需求: 股民买卖股票 初步代码: # -*- encoding: utf-8 -*- #股票1 class Stock1 def buy puts '股票1买入' end def sell puts ...
- FTP服务器配置实践
1.为linux系统分配IP地址:192.168.X.1/24,并重启网络服务,客户端XP系统IP地址为:192.168.X.2/24, 2.查询本机是否安装了vsftpd服务,结果显示未安装,挂载光 ...
- Vue-cli proxyTable 解决开发环境的跨域问题
Vue-cli proxyTable 解决开发环境的跨域问题 proxyTable: { '/list': { target: 'http://api.xxxxxxxx.com', pathRewri ...
- navicat中文破解版,navicat破解版,navicat for mysql10.0.11简体中文破解版
https://blog.csdn.net/weixin_40426638/article/details/78933585 下载链接如下(里面有破解码) https://pan.baidu.com/ ...
- 使用vux实现上拉刷新的总结
最近公司在研发app,选择了基于Vue框架的vux组件库,现总结在实现上拉刷新功能遇到的坑: 1.问题:只刷新一次,解决方法:需要自己手动重置状态 this.scrollerStatus.pullup ...
- Django学习笔记之form组件的局部钩子和全局钩子
本文通过注册页面的form组件,查看其中使用的全局钩子和局部钩子. # Create your views here. class RegForm(forms.Form): username = fo ...