Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如果可能的话,如何获得获得一个数组的2个元素所需的迭代次数?_Python_Algorithm - Fatal编程技术网

Python 如果可能的话,如何获得获得一个数组的2个元素所需的迭代次数?

Python 如果可能的话,如何获得获得一个数组的2个元素所需的迭代次数?,python,algorithm,Python,Algorithm,我对算法相当陌生,我正在处理一个无法完全翻译成数学语言的问题 因此,给我数组[1,1],我每一步只能在它们的数字之间执行一次求和,即你只能选择: [x(s+1), y(s+1)]=[x(s)+y(s),y(s)] 或 但这两者不能同时存在 因此, 目标是了解获得给定[x,y]数组需要多少步骤 到目前为止,我知道 if (min(x,y)==1): steps =max(x,y)-1 if (x%2 ==0 and y%2==0): steps= not possible if (

我对算法相当陌生,我正在处理一个无法完全翻译成数学语言的问题

因此,给我数组[1,1],我每一步只能在它们的数字之间执行一次求和,即你只能选择:

[x(s+1), y(s+1)]=[x(s)+y(s),y(s)]

但这两者不能同时存在

因此,

目标是了解获得给定[x,y]数组需要多少步骤

到目前为止,我知道

if (min(x,y)==1):
   steps =max(x,y)-1

if (x%2 ==0 and y%2==0):
   steps= not possible
if (max(x,y)%min(x,y) == 0):
   steps= not possible
if (x%3 ==0 and y%3==0):
   steps= not possible
此外,我还为每对(x,y)绘制了需要多少步,我可以看到x或y的每一个倍数都会出现一个模式,但当x或y大于等于5时,我无法将其作为数学函数来编写

任何指导都将不胜感激


在绘图中,标记为1的行应该有点,一直到40。同样,标记为1的列应该有点,一直到30。因此,绘图缺少一些关键信息,这使得模式很难识别

这是一个不同的形象。起点
[1,1]
位于左上角<代码>1s是可访问的,
0
s是不可访问的。注意

  • 对于任何
    x
  • x
    为奇数时,可以访问
    [2,x]
  • x
    不是3的倍数时,可以访问
    [3,x]
  • x
    不是2的倍数时,可以访问
    [4,x]
  • x
    不是5的倍数时,可以访问
    [5,x]
  • x
    不是2或3的倍数时,可以访问
    [6,x]
  • 一般来说,当gcd(y,x)=1时,
    [y,x]
    是可到达的
123456
123456789012345678901234567890123456789012345678901234567890123
+---------------------------------------------------------------
1 |111111111111111111111111111111111111111111111111111111111111111
2 |101010101010101010101010101010101010101010101010101010101010101
3 |110110110110110110110110110110110110110110110110110110110110110
4 |101010101010101010101010101010101010101010101010101010101010101
5 |111101111011110111101111011110111101111011110111101111011110111
6 |100010100010100010100010100010100010100010100010100010100010100
7 |111111011111101111110111111011111101111110111111011111101111110
8 |101010101010101010101010101010101010101010101010101010101010101
9 |110110110110110110110110110110110110110110110110110110110110110
10 |101000101010100010101010001010101000101010100010101010001010101
11 |111111111101111111111011111111110111111111101111111111011111111
12 |100010100010100010100010100010100010100010100010100010100010100
13 |111111111111011111111111101111111111110111111111111011111111111
14 |101010001010101010100010101010101000101010101010001010101010100
15 |110100110010110110100110010110110100110010110110100110010110110
16 |101010101010101010101010101010101010101010101010101010101010101
17 |111111111111111101111111111111111011111111111111110111111111111
18 |100010100010100010100010100010100010100010100010100010100010100
19 |111111111111111111011111111111111111101111111111111111110111111
20 |101000101010100010101010001010101000101010100010101010001010101
21 |110110010110100110110110110010110100110110110110010110100110110
22 |101010101000101010101010101010100010101010101010101010001010101
23 |111111111111111111111101111111111111111111111011111111111111111
24 |100010100010100010100010100010100010100010100010100010100010100
25 |111101111011110111101111011110111101111011110111101111011110111
26 |101010101010001010101010101010101010100010101010101010101010101
27 |110110110110110110110110110110110110110110110110110110110110110
28 |101010001010101010100010101010101000101010101010001010101010100
29 |111111111111111111111111111101111111111111111111111111111011111
30 |100000100010100010100010000010100000100010100010100010000010100
31 |111111111111111111111111111111011111111111111111111111111111101
32 |101010101010101010101010101010101010101010101010101010101010101
33 |110110110100110110110010110110110110110110100110110110010110110
34 |101010101010101000101010101010101010101010101010100010101010101
35 |111101011011100111100111011010111101111010110111001111001110110
36 |100010100010100010100010100010100010100010100010100010100010100
37 |111111111111111111111111111111111111011111111111111111111111111
38 |101010101010101010001010101010101010101010101010101010100010101
39 |110110110110010110110110100110110110110110110110110010110110110
40 |101000101010100010101010001010101000101010100010101010001010101
41 |111111111111111111111111111111111111111101111111111111111111111
42 |100010000010100010100010100010100000100010100010000010100010100
43 |111111111111111111111111111111111111111111011111111111111111111
44 |101010101000101010101010101010100010101010101010101010001010101
45 |110100110010110110100110010110110100110010110110100110010110110
46 |101010101010101010101000101010101010101010101010101010101010101
47 |111111111111111111111111111111111111111111111101111111111111111
48 |100010100010100010100010100010100010100010100010100010100010100
49 |111111011111101111110111111011111101111110111111011111101111110
50 |101000101010100010101010001010101000101010100010101010001010101
51 |110110110110110100110110110110110010110110110110110110110110110
52 |101010101010001010101010101010101010100010101010101010101010101
53 |111111111111111111111111111111111111111111111111111101111111111
54 |100010100010100010100010100010100010100010100010100010100010100
55 |111101111001110111101011011110110101111011100111101111011110111
56 |101010001010101010100010101010101000101010101010001010101010100
57 |110110110110110110010110110110110110100110110110110110110110110
58 |101010101010101010101010101000101010101010101010101010101010101
59 |111111111111111111111111111111111111111111111111111111111101111
60 |100000100010
0: [1,1]
1: [2,1],                      [1,2]
2: [3,1],        [2,3],        [3,2],        [1,3]
3: [4,1], [3,4], [5,3], [2,5], [5,2], [3,5], [4,3], [1,4]
...and so on.
if (min(x,y)==1):
   steps =max(x,y)-1

if (x%2 ==0 and y%2==0):
   steps= not possible
if (max(x,y)%min(x,y) == 0):
   steps= not possible
if (x%3 ==0 and y%3==0):
   steps= not possible