import gmpy2
def discreteLog(g,p,a): #离散对数,求 g^x=a mod p中的x
table={}
sq=gmpy2.isqrt(p-1)
m=gmpy2.add(sq,1) #向上取整
for i in range(m):
k=-i*m
y=gmpy2.powmod(g,k,p)
mod=((a%p)*y)%p
table.update({mod:i})
j=0
while True:
result=gmpy2.powmod(g,j,p)
if result in table.keys():
sa=m*table[result]+j
return sa
#return table[result],m #将对应的下标返回
else:
j=j+1 p=93450983094850938450983409623
a=45416776270485369791375944998 x=discreteLog(-2,p,a)
print(x)

小的可以,大的数就报错“Memory error”了

Discrete Log Algorithms :Baby-step giant-step 【二】的更多相关文章

  1. POJ 2417 Discrete Logging ( Baby step giant step )

    Discrete Logging Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 3696   Accepted: 1727 ...

  2. 解高次同余方程 (A^x=B(mod C),0<=x<C)Baby Step Giant Step算法

    先给出我所参考的两个链接: http://hi.baidu.com/aekdycoin/item/236937318413c680c2cf29d4 (AC神,数论帝  扩展Baby Step Gian ...

  3. 数论之高次同余方程(Baby Step Giant Step + 拓展BSGS)

    什么叫高次同余方程?说白了就是解决这样一个问题: A^x=B(mod C),求最小的x值. baby step giant step算法 题目条件:C是素数(事实上,A与C互质就可以.为什么?在BSG ...

  4. [置顶] hdu2815 扩展Baby step,Giant step入门

    题意:求满足a^x=b(mod n)的最小的整数x. 分析:很多地方写到n是素数的时候可以用Baby step,Giant step, 其实研究过Baby step,Giant step算法以后,你会 ...

  5. HDU 2815 Mod Tree 离散对数 扩张Baby Step Giant Step算法

    联系:http://acm.hdu.edu.cn/showproblem.php?pid=2815 意甲冠军: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQ ...

  6. 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 ...

  7. 【POJ2417】baby step giant step

    最近在学习数论,然而发现之前学的baby step giant step又忘了,于是去翻了翻以前的代码,又复习了一下. 觉得总是忘记是因为没有彻底理解啊. 注意baby step giant step ...

  8. 『高次同余方程 Baby Step Giant Step算法』

    高次同余方程 一般来说,高次同余方程分\(a^x \equiv b(mod\ p)\)和\(x^a \equiv b(mod\ p)\)两种,其中后者的难度较大,本片博客仅将介绍第一类方程的解决方法. ...

  9. HDU 2815 扩展baby step giant step 算法

    题目大意就是求 a^x = b(mod c) 中的x 用一般的baby step giant step 算法会超时 这里参考的是http://hi.baidu.com/aekdycoin/item/2 ...

随机推荐

  1. python 3.7 方向键乱码

    原因是缺少安装包libreadline-dev 第一步安装libreadline-dev包:sudo apt-get install libreadline-dev(centos安装:yum -y i ...

  2. 在static的function静态函数中访问成员变量

    class A{ private $url; public function __construct(){ $this->url = $_SERVER['PATCH_INFO']; } publ ...

  3. P3690 【模板】Link Cut Tree (动态树)

    P3690 [模板]Link Cut Tree (动态树) 认父不认子的lct 注意:不 要 把 $fa[x]$和$nrt(x)$ 混 在 一 起 ! #include<cstdio> v ...

  4. k8s tensorflow

    Online learning github source Kubeflow实战系列 Prepare 了解ksonnet初探Google之Kubeflow (采用的是0.8.0)install dep ...

  5. Codeforces 868D Huge Strings - 位运算 - 暴力

    You are given n strings s1, s2, ..., sn consisting of characters 0 and 1. m operations are performed ...

  6. USB通信基础知识

    1 USB系统组成 主机:提供USB接口和接口管理功能的硬件.软件.固件的复合体.PC机或OTG设备,一个USB系统只能有一个主机 设备:1.集线器HUB:扩展主机接口,设备可以通过其接入主机  2. ...

  7. iOS字体大小

    1,iOS 字体大小单位是pt——磅. 英文字体的1磅,相当于1/72 英寸,约等于1/2.8mm. px:相对长度单位.像素(Pixel).(PS字体) pt:绝对长度单位.点(Point).(iO ...

  8. topcoder srm 480 div1

    problem1 link 直接模拟即可. problem2 link 首先,网关一定是安装在client与server之间的链路上.而不会安装在client与client之间的链路上.对于一条路径c ...

  9. topcoder srm 330 div1

    problem1 link 直接模拟. import java.util.*; import java.math.*; import static java.lang.Math.*; public c ...

  10. Python3基础 list del 从内存中删除整个列表

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...