水,汇编- ;Collatz猜想
- ;Code By 老刘
- ;环境:MASM32 SDK
- ;编译指令:ml /coff Collatz猜想.asm /link /subsystem:console
- ;参数:需要验证猜想的数。
- ;没写高精度,所以输入或计算中途的超过2^32 - 1的数会有溢出。
- ;参考:MHL批处理标准教程之3n+1猜想。
-
-
- Include masm32rt.inc
- Main Proto
-
- .Data?
- bBuffer DB 11 Dup (?)
- dwInput DD ?
- dwCrLfZero DD ?
- dwJumpPlusOne DD ?
- ;End Data?
-
- .Code
- Main Proc
- ;获得参数
- Invoke ArgClC,1,Offset bBuffer
- Sub Esp,4
- Invoke atodw_ex,Offset bBuffer
- Add Esp,4
- Mov dwInput,Eax
-
- Push Eax
- Invoke StdOut,cfm$("{")
- Pop Eax
- ;开始标记
- Xor Ecx,Ecx ;计数器
- .While Eax > 1
- PushAD
- Invoke dw2a,Eax,Offset bBuffer
- Invoke StdOut,Offset bBuffer
- Invoke StdOut,cfm$(",")
- PopAD
- Inc Ecx
- Mov Ebx,Eax
- Shr Eax,1
- Mov Edx,Eax ;除以2并取整数部分的结果
- Shl Eax,1
- .If Eax == Ebx
- Mov Eax,Edx
- .Else
- Lea Eax,[2*Ebx+Ebx+1]
- .EndIf
- .EndW
-
- Push Ecx
- Invoke StdOut,cfm$("1}\n")
- Invoke StdOut,cfm$("表长:")
- Pop Ecx
- Inc Ecx
- Invoke dw2a,Ecx,Offset bBuffer
- Invoke StdOut,Offset bBuffer
- Invoke StdOut,cfm$("\n")
-
- Ret
- Main EndP
-
- Start:
- Call Main
- Invoke ExitProcess,NULL
- End Start
- End
复制代码
- {1}
- 表长:1
- {2,1}
- 表长:2
- {3,10,5,16,8,4,2,1}
- 表长:8
- {4,2,1}
- 表长:3
- {5,16,8,4,2,1}
- 表长:6
- {6,3,10,5,16,8,4,2,1}
- 表长:9
- {7,22,11,34,17,52,26,13,40,20,10,5,16,8,4,2,1}
- 表长:17
- {8,4,2,1}
- 表长:4
- {9,28,14,7,22,11,34,17,52,26,13,40,20,10,5,16,8,4,2,1}
- 表长:20
- {10,5,16,8,4,2,1}
- 表长:7
- {11,34,17,52,26,13,40,20,10,5,16,8,4,2,1}
- 表长:15
- {12,6,3,10,5,16,8,4,2,1}
- 表长:10
- {13,40,20,10,5,16,8,4,2,1}
- 表长:10
- {14,7,22,11,34,17,52,26,13,40,20,10,5,16,8,4,2,1}
- 表长:18
- {15,46,23,70,35,106,53,160,80,40,20,10,5,16,8,4,2,1}
- 表长:18
- {16,8,4,2,1}
- 表长:5
- {17,52,26,13,40,20,10,5,16,8,4,2,1}
- 表长:13
- {18,9,28,14,7,22,11,34,17,52,26,13,40,20,10,5,16,8,4,2,1}
- 表长:21
- {19,58,29,88,44,22,11,34,17,52,26,13,40,20,10,5,16,8,4,2,1}
- 表长:21
- {20,10,5,16,8,4,2,1}
- 表长:8
- {21,64,32,16,8,4,2,1}
- 表长:8
- {22,11,34,17,52,26,13,40,20,10,5,16,8,4,2,1}
- 表长:16
- {23,70,35,106,53,160,80,40,20,10,5,16,8,4,2,1}
- 表长:16
- {24,12,6,3,10,5,16,8,4,2,1}
- 表长:11
- {25,76,38,19,58,29,88,44,22,11,34,17,52,26,13,40,20,10,5,16,8,4,2,1}
- 表长:24
- {26,13,40,20,10,5,16,8,4,2,1}
- 表长:11
- {27,82,41,124,62,31,94,47,142,71,214,107,322,161,484,242,121,364,182,91,274,137,412,206,103,310,155,466,233,700,350,175,526,263,790,395,1186,593,1780,890,445,1336,668,334,167,502,251,754,377,1132,566,283,850,425,1276,638,319,958,479,1438,719,2158,1079,3238,1619,4858,2429,7288,3644,1822,911,2734,1367,4102,2051,6154,3077,9232,4616,2308,1154,577,1732,866,433,1300,650,325,976,488,244,122,61,184,92,46,23,70,35,106,53,160,80,40,20,10,5,16,8,4,2,1}
- 表长:112
- {28,14,7,22,11,34,17,52,26,13,40,20,10,5,16,8,4,2,1}
- 表长:19
- {29,88,44,22,11,34,17,52,26,13,40,20,10,5,16,8,4,2,1}
- 表长:19
- {30,15,46,23,70,35,106,53,160,80,40,20,10,5,16,8,4,2,1}
- 表长:19
- {31,94,47,142,71,214,107,322,161,484,242,121,364,182,91,274,137,412,206,103,310,155,466,233,700,350,175,526,263,790,395,1186,593,1780,890,445,1336,668,334,167,502,251,754,377,1132,566,283,850,425,1276,638,319,958,479,1438,719,2158,1079,3238,1619,4858,2429,7288,3644,1822,911,2734,1367,4102,2051,6154,3077,9232,4616,2308,1154,577,1732,866,433,1300,650,325,976,488,244,122,61,184,92,46,23,70,35,106,53,160,80,40,20,10,5,16,8,4,2,1}
- 表长:107
- {32,16,8,4,2,1}
- 表长:6
- {33,100,50,25,76,38,19,58,29,88,44,22,11,34,17,52,26,13,40,20,10,5,16,8,4,2,1}
- 表长:27
- {34,17,52,26,13,40,20,10,5,16,8,4,2,1}
- 表长:14
- {35,106,53,160,80,40,20,10,5,16,8,4,2,1}
- 表长:14
- {36,18,9,28,14,7,22,11,34,17,52,26,13,40,20,10,5,16,8,4,2,1}
- 表长:22
- {37,112,56,28,14,7,22,11,34,17,52,26,13,40,20,10,5,16,8,4,2,1}
- 表长:22
- {38,19,58,29,88,44,22,11,34,17,52,26,13,40,20,10,5,16,8,4,2,1}
- 表长:22
- {39,118,59,178,89,268,134,67,202,101,304,152,76,38,19,58,29,88,44,22,11,34,17,52,26,13,40,20,10,5,16,8,4,2,1}
- 表长:35
- {40,20,10,5,16,8,4,2,1}
- 表长:9
- {41,124,62,31,94,47,142,71,214,107,322,161,484,242,121,364,182,91,274,137,412,206,103,310,155,466,233,700,350,175,526,263,790,395,1186,593,1780,890,445,1336,668,334,167,502,251,754,377,1132,566,283,850,425,1276,638,319,958,479,1438,719,2158,1079,3238,1619,4858,2429,7288,3644,1822,911,2734,1367,4102,2051,6154,3077,9232,4616,2308,1154,577,1732,866,433,1300,650,325,976,488,244,122,61,184,92,46,23,70,35,106,53,160,80,40,20,10,5,16,8,4,2,1}
- 表长:110
- {42,21,64,32,16,8,4,2,1}
- 表长:9
- {43,130,65,196,98,49,148,74,37,112,56,28,14,7,22,11,34,17,52,26,13,40,20,10,5,16,8,4,2,1}
- 表长:30
- {44,22,11,34,17,52,26,13,40,20,10,5,16,8,4,2,1}
- 表长:17
- {45,136,68,34,17,52,26,13,40,20,10,5,16,8,4,2,1}
- 表长:17
- {46,23,70,35,106,53,160,80,40,20,10,5,16,8,4,2,1}
- 表长:17
- {47,142,71,214,107,322,161,484,242,121,364,182,91,274,137,412,206,103,310,155,466,233,700,350,175,526,263,790,395,1186,593,1780,890,445,1336,668,334,167,502,251,754,377,1132,566,283,850,425,1276,638,319,958,479,1438,719,2158,1079,3238,1619,4858,2429,7288,3644,1822,911,2734,1367,4102,2051,6154,3077,9232,4616,2308,1154,577,1732,866,433,1300,650,325,976,488,244,122,61,184,92,46,23,70,35,106,53,160,80,40,20,10,5,16,8,4,2,1}
- 表长:105
- {48,24,12,6,3,10,5,16,8,4,2,1}
- 表长:12
- {49,148,74,37,112,56,28,14,7,22,11,34,17,52,26,13,40,20,10,5,16,8,4,2,1}
- 表长:25
- {50,25,76,38,19,58,29,88,44,22,11,34,17,52,26,13,40,20,10,5,16,8,4,2,1}
- 表长:25
复制代码
|