Baby-step giant-step算法
写在前面:
学习笔记,方便复习,学习资料来自网络,注明出处
我们都在努力奔跑,我们都是追梦人

结论
|
In group theory, a branch of mathematics, the baby-step giant-step is a meet-in-the-middle algorithm for computing the discrete logarithm The algorithm is based on a space–time tradeoff. It is a fairly simple modification of trial multiplication, the naive method of finding discrete logarithms ——Wikipedia |
|
译: 在群论中,作为数学的一个分支,BSGS算法是计算离散对数的一种中间交集算法 该算法时间复杂度/空间复杂度相权衡。是对试乘法的一个相当简单的修改,这是一种求离散对数的幼稚方法 |
实现
裸的Baby-step giant-step算法
首先,要知道什么是[◹]离散对数
BSGS算法的输入输出:
输入:一个n阶的模群G,群元素β
输出:一个整数x,满足αx ≡ β (G中)
实际上是[◹]拓展欧几里得算法的应用③
已知正整数a,b,素数p,保证给出的a,p互素,求一个整数x使满足ax ≡ b (MOD p)

希望求得x,把x拆一下,拆成⌈p⌉*i+n
其中:
0<=i<⌈p⌉
0<=n<⌈p⌉
(A⌈p⌉)i*An ≡ B (mod p)
这里使用[◹]拓展欧几里得算法的应用②
因为p是质数,且a,p互素,保证了解的存在,自然能求出来一个解
如果需要多解,从小到大枚举i,那么得到的x也就从小到大
至于An,知道了An等于几,怎么知道n是几呢?
有一个很聪(diu)明(ren)的方法,事先把An与n存到hash表(或者map)里(占一定时间),查一下就好了
当然,如果没有特别说明a,p互素,需要考虑不互素的情况,a是p的倍数或者a==0时(a%p==0):
①b==1,则当a!=0时,除了零以外任何数的0次方都等于1,若a==0,无解
②b==0,则x可以取0以外任意正整数
Baby-step giant-step算法的更多相关文章
- POJ 3243 Clever Y (求解高次同余方程A^x=B(mod C) Baby Step Giant Step算法)
不理解Baby Step Giant Step算法,请戳: http://www.cnblogs.com/chenxiwenruo/p/3554885.html #include <iostre ...
- 解高次同余方程 (A^x=B(mod C),0<=x<C)Baby Step Giant Step算法
先给出我所参考的两个链接: http://hi.baidu.com/aekdycoin/item/236937318413c680c2cf29d4 (AC神,数论帝 扩展Baby Step Gian ...
- HDU 2815 Mod Tree 离散对数 扩张Baby Step Giant Step算法
联系:http://acm.hdu.edu.cn/showproblem.php?pid=2815 意甲冠军: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQ ...
- 『高次同余方程 Baby Step Giant Step算法』
高次同余方程 一般来说,高次同余方程分\(a^x \equiv b(mod\ p)\)和\(x^a \equiv b(mod\ p)\)两种,其中后者的难度较大,本片博客仅将介绍第一类方程的解决方法. ...
- HDU 2815 扩展baby step giant step 算法
题目大意就是求 a^x = b(mod c) 中的x 用一般的baby step giant step 算法会超时 这里参考的是http://hi.baidu.com/aekdycoin/item/2 ...
- 【学习笔记】Baby Step Giant Step算法及其扩展
1. 引入 Baby Step Giant Step算法(简称BSGS),用于求解形如\(a^x\equiv b\pmod p\)(\(a,b,p\in \mathbb{N}\))的同余方程,即著名的 ...
- 数论之高次同余方程(Baby Step Giant Step + 拓展BSGS)
什么叫高次同余方程?说白了就是解决这样一个问题: A^x=B(mod C),求最小的x值. baby step giant step算法 题目条件:C是素数(事实上,A与C互质就可以.为什么?在BSG ...
- [置顶] hdu2815 扩展Baby step,Giant step入门
题意:求满足a^x=b(mod n)的最小的整数x. 分析:很多地方写到n是素数的时候可以用Baby step,Giant step, 其实研究过Baby step,Giant step算法以后,你会 ...
- POJ 2417 Discrete Logging ( Baby step giant step )
Discrete Logging Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 3696 Accepted: 1727 ...
- 【POJ2417】baby step giant step
最近在学习数论,然而发现之前学的baby step giant step又忘了,于是去翻了翻以前的代码,又复习了一下. 觉得总是忘记是因为没有彻底理解啊. 注意baby step giant step ...
随机推荐
- Nginx Consul nginx-upsync-module
nginx consul nginx-upsync-module 依赖包: yum -y install libpcre3 libpcre3-dev ruby zlib1g-dev patch 下载n ...
- sort方法和sorted()函数
sort方法和sorted()函数的区别: 相同点:都能完成排序操作. 不同点: (1)使用sort()方法对list排序会修改list本身,不会返回新list,sort()不能对dict字典进行排序 ...
- 转发:[服务器]SSL安装证书教程
[服务器]SSL安装证书教程 来自阿里云教程 Tomcat服务器安装SSL证书 安装PFX格式证书 https://help.aliyun.com/document_detail/98576.ht ...
- Electron实用技巧-开机启动时隐藏主窗口,只显示系统托盘
# 1 在桌面软件中,开机自启动是很常见的功能,在electron中也提供了很好的支持,以下是主要代码: //应用是否打包if (app.isPackaged) { //设置开机启动 app.se ...
- C++ STL 栈和队列
栈和队列 头文件 #include<queue> // 队列 #include<stack> //栈 定义方式 //参数就是数据类型 stack<int> s; q ...
- web项目启动链接mysql巨慢
说明:项目部署到测试服务器上,mysql部署在另一台服务器上,项目第一次启动之后登陆后台很慢,大概30s左右,经查发现第一次访问数据库的时候会通过DNS解析客户端机器域名,mysql还有DNS反向解析 ...
- kubernetes备份恢复之velero
Velero备份.恢复.迁移Kubernetes集群 Velero简介 Velero 地址:https://github.com/vmware-tanzu/velero Velero属于VMWare开 ...
- python的零碎知识
1.Python代码操作git 安装 pip3 install gitpython 操作git import os from git.repo import Repo # gitpython def ...
- Flask源码关于local的实现
flask源码关于local的实现 try: # 协程 from greenlet import getcurrent as get_ident except ImportError: try: fr ...
- IPC图像处理项目流程图
网络摄像机IPC图像处理项目流程图: