我正在尝试制作一个程序来评估 3 个数字(基数)的 gcd,如果base1
and base2
、base2
andbase3
和base3
and的 GCDbase1
都等于 1,则将基数评估为一个范围内的指数。基本上,我需要做的是弄清楚他们的 GCD 是否等于 1,然后计算数字的幂。这是它的样子:
bases = 150
powers = 150
base1 = all numbers 1-bases
base2 = all numbers 1-bases
base3 = all numbers 1-bases
if the GCD of all combinations = 1
do base1^all numbers 3-powers
do base2^all numbers 3-powers
do base2^all numbers 3-powers
then store all of those in an array
现在,我尝试使用可怕的for
循环,但它非常慢,我不认为它是一个解决方案。只有当基地和权力是 10 或以下时,它才能快速工作。我怎么能不使用for
循环来做到这一点?或者,如果我必须使用for
循环,我怎样才能减少使用的数量?我可以计算出 3 个 GCD 组合等于 1 的数字吗?for
我尝试过的循环如下:
for i = 1:numbers
for j = 1:numbers
for k = 1:numbers
if gcd(i,j) == 1 && gcd(i,k) == 1 && gcd(k,j) == 1
for a = 3:powers
for b = 3:powers
for c = 3: powers
x = i^a
y = j^b
z = k^c
end
end
end
end
end
end
end