题目链接: https://cn.vjudge.net/problem/POJ-2429 题目大意: 给出两个数的gcd和lcm,求原来的这两个数(限定两数之和最小). 解题思路: 首先,知道gcd和lcm求原来的两个数,需要分解lcm / gcd .将其分解为互质的两个数. 首先将lcm/gcd质因数分解,要分解出沪互质两个数字,那么这两个数字的gcd=1,也就是没有公共的质因子,所以可以直接枚举这两个数字的质因子,如果一个数要取这个质因子,就把它的指数全部取掉. 质因数分解用大数因式分解来做…
python解决方案 nums = [1,2,3,4,5,6] #假如这是给定的数组 target = 9 #假如这是给定的目标值 num_list = [] #用来装结果的容器 def run(nums,target): '''功能函数''' for num1 in nums: for num2 in nums: if num1 + num2 == target: num_list.append(num1) num_list.append(num2) print(num_list) break…
GCD & LCM Inverse Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 10621   Accepted: 1939 Description Given two positive integers a and b, we can easily calculate the greatest common divisor (GCD) and the least common multiple (LCM) of a…
GCD & LCM Inverse Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9928   Accepted: 1843 Description Given two positive integers a and b, we can easily calculate the greatest common divisor (GCD) and the least common multiple (LCM) of a a…
根据最大公约数和最小公倍数求原来的两个数 题目大意,不翻译了,就是上面链接的意思. 具体思路就是要根据数论来,设a和b的GCD(最大公约数)和LCM(最小公倍数),则a/GCD*b/GCD=LCM/GCD,我们只用枚举LCM/GCD的所有质因数就可以了,然后把相应的质因数乘以GCD即可得出答案. 找素数很简单,用Miller_Rabin求素数的方法,可以多求几次提高正确率,原理就是用的费马定理:如果P是素数,则A^(p-1)mod P恒等于1,为了绕过Carmichael数,采用费马小定理:如果…
题意:给出a和b的gcd和lcm,让你求a和b.按升序输出a和b.若有多组满足条件的a和b,那么输出a+b最小的.思路:lcm=a*b/gcd   lcm/gcd=a/gcd*b/gcd 可知a/gcd与b/gcd互质,由此我们可以先用Pollard_rho法对lcm/gcd进行整数分解, 然后对其因子进行深搜找出符合条件的两个互质的因数,然后再都乘以gcd即为输出答案. #include <iostream> #include <stdio.h> #include <alg…
Given two positive integers a and b, we can easily calculate the greatest common divisor (GCD) and the least common multiple (LCM) of a and b. But what about the inverse? That is: given GCD and LCM, finding a and b. Input The input contains multiple…
题目大意 给定两个数a,b的GCD和LCM,要求你求出a+b最小的a,b 题解 GCD(a,b)=G GCD(a/G,b/G)=1 LCM(a/G,b/G)=a/G*b/G=a*b/G^2=L/G 这样的话我们只要对L/G进行质因数分解,找出最接近√(L/G)的因子p,最终结果就是a=p*G,b=L/p,对(L/G)就是套用Miller–Rabin和Pollard's rho了,刚开始Pollard's rho用的函数也是 f(x)=x^2+1,然后死循环了....改成f(x)=x^2+c(c<…
原题链接:http://poj.org/problem?id=2429 GCD & LCM Inverse Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 17639 Accepted: 3237 Description Given two positive integers a and b, we can easily calculate the greatest common divisor (GCD) and the l…
GCD & LCM Inverse Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9756Accepted: 1819 Description Given two positive integers a and b, we can easily calculate the greatest common divisor (GCD) and the least common multiple (LCM) of a and b.…