使用Pollard rho算法计算两个大整数的最小公倍数
来源:互联网 发布:网络作家富豪榜 2016 编辑:程序博客网 时间:2024/05/01 16:45
本文主要介绍基本思路和具体的python代码实现
Pollard rho算法基本思路
1、F(x)=x^2+a 中的a可以试情况而定,一般取1,但尽量不要取0和2;
2、种子默认取2,原则上不小于2;
3、Pollard算法可以快速获取数n的几个因子,但这些因子不是n的质因子,也不是n的所有因子;
4、通过限定x>n , 规避循环问题。
使用Pollard rho算法求最小公倍数的基本思路
本方法只经过有限验证,不保证一定正确,仅做参考。
具体python2.7代码如下:
# !/user/bin/env python# -*-coding: utf-8 -*-'''Using Pollard Pho factoring to find LCM(a, b)seed = 2, f(x) = x^2 + 1'''from fractions import gcd# find the factors of n with large powerdef Pollard(n): # generate the list(List_x) of x x = 2 f = lambda x: x * x + 1 List_x = [2] while x < n: x = f(x) List_x.append(x) List_x = [x % n for x in List_x] # calculate p = gcd(x(i) - x(j), n) and remove the same p List_p = [gcd((List_x[i] - List_x[j]), n) for i in range(1, len(List_x)) for j in range(i)] List_p = list(set(List_p)) List_p.sort() # list factors of n List_factor = [p for p in List_p if p > 1] return List_factorprint 'Using Pollard Pho factoring to find LCM(a, b)'print 'seed = 2, f(x) = x^2 + 1'a = int(raw_input('input a:'))b = int(raw_input('input b:'))#obtain the factors of a and b, remove one of the same factor of bothprime_a = [a / i for i in Pollard(a)] + Pollard(a)prime_b = [b / i for i in Pollard(b)] + Pollard(b)temp = list(set(prime_a + prime_b))temp.sort()prime = [i for i in temp if i != 1]#calculate LCM(a, b)LCM = a * bfor i in prime: while (LCM / i % a == 0) and (LCM / i % b == 0): LCM = LCM / iprint '\nLCM(a, b) = %d\n' % LCMraw_input('Press Enter to exit()')
1 0
- 使用Pollard rho算法计算两个大整数的最小公倍数
- Pollard Rho 大整数分解
- Pollard-rho大整数分解
- 大整数分解——Pollard Rho算法
- Java实现的大整数分解Pollard's rho算法程序
- C++实现的大整数分解Pollard's rho算法程序
- 整数因子分解的Pollard-rho方法
- pollard's rho算法(使用GMP库)
- 对Pollard's Rho算法的理解
- Pollard Rho算法思想
- Miller-Rabin素数测试和Pollard-rho大整数分解
- Pollard rho整数分解法
- Miller_Rabin算法&&Pollard-Rho算法
- Miller_Rabin和Pollard Rho算法
- 质因数分解的一些讨论(Pollard-Rho算法)
- LG的数学计划----分解质因数(Pollard-Rho算法)
- Java实现算法导论中Pollard的rho启发式方法
- Pollard的rho启发式因子分解算法 & [CodeVS 4939] 欧拉函数:Miller-Rabin + Pollard-rho 质因数分解
- 使用telnet发送邮件的若干问题。。。
- Excel学习笔记(1)——数据类型,自动填充,数据有效性,美化
- RTSP 协议 简单交互过程
- [心得]面试题分析与整理3
- 使用FragmentTabHost实现类似微信底部的效果
- 使用Pollard rho算法计算两个大整数的最小公倍数
- tomcat在Debug模式下无法启动解决办法
- 【LeetCode】301. Remove Invalid Parentheses
- 最轻的天平
- 一个关于指针数组的例子
- 【JAVA设计模式】——设计原则
- caffe学习系列四Sigmod、Tanh、ReLU等Layer源码分析
- 杭电ACM2004题(成绩转换)-----C语言
- 中文在URL中的编码