我尝试使用原始数字2 3 5 7和11生成一个大数字,然后我尝试将其分解并且它不起作用。问题是它没有完全分解它。这里是代码:(所有print()都用于检查程序是否正确)
y = int(random.randrange(0, 20))
print((2**y))
z = int(random.randrange(0, 20))
print(z)
c = int(random.randrange(0, 20))
print(c)
v = int(random.randrange(0, 20))
print(v)
j = int(random.randrange(0, 20))
print(j)
e = int(((2**y)*(3**z)*(5**c)*(7**v)*(11**j)))
for n in range (0, 200):
if (e % 2) == 0:
x = int(e / 2)
print(x)
elif (x % 3) == 0:
x = int(x / 3)
print(x)
elif (x % 5) == 0:
x = int(x / 5)
print(x)
elif (x % 7) == 0:
x = int(x / 7)
print(x)
elif (x % 11) == 0:
x = int(x / 11)
print(x)
答案 0 :(得分:0)
您永远不会更改您要考虑的数字:每次都以原始数字开头。要解决此问题,在进行除法时,只需将结果分配给原始文件:
end
或者更简单地说,
if (e % 2) == 0:
e = int(e/2)
请注意,您现在必须将所有 x 引用更改为 e :
e //= 2 # Integer division, attached to the equals sign.