1
A
回答
0
鑑於像B111 ... 10111 ... ... 1BBB,輸入其中的1的第一字符串是(即,1^A)的一元編碼和所述第二串1s是b的一元編碼(即1^b),我們可以設計一個單帶確定性圖靈機來計算一個mod b(通過在留下磁帶上留下的一個mod b的一元表示後進入暫停接受) 。
首先注意一個mod b < a,所以我們可以通過從a的一元表示中刪除一些1,並從b的一元表示中刪除所有的1來恢復mod b的一元表示。注意到mod b =(a - b)mod b,至少當a> = b;當一個< b,那麼一個mod b = a。這個觀察結果表明,我們可以從a的一元表示中刪除b 1,直到剩餘的b 1少於b 1,此時我們從b的表示中刪除1,並停止接受。
僞代碼:
move right until you find a blank.
move one step to the left.
you are now looking at the last 1 in b's representation.
mark this as Y and move left until you find 0.
move left until you find a 1 or blank.
you are now looking at the last 1 in a's representation, or blank.
if 1, mark this as X and move right until you find Y.
if blank, a < b; change all Xs to 1s and all 0s, 1s and YBs to blanks. halt-accept.
move one step to the left.
you are now looking at the last 1 in b's representation, or 0.
if 1, continue as above.
if 0, b < a; change all Xs to 0s, all Ys to 1s, and restart from the beginning
舉例:10 MOD 3
B11111111110111BBB...
^
B11111111110111BBB...
^ move right until you find a blank
B11111111110111BBB...
^ move one step to the left. looking at last 1 in b
B1111111111011YBBB...
^ mark as Y and move left to 0
B1111111111011YBBB...
^ move one step to the left. looking at last 1 in a.
B111111111X011YBBB...
^ mark as X and move right to Y
B111111111X011YBBB...
^ move one step to the left. looking at last 1 in b.
B111111111X01YYBBB...
^ mark as Y and move left to 0
B111111111X01YYBBB...
^ move left to 1
B11111111XX01YYBBB...
^ mark as X and move right to Y
B11111111XX01YYBBB...
^ move one step to the left. looking at last 1 in b
B11111111XX0YYYBBB...
^ mark as Y and move left to 0
B11111111XX0YYYBBB...
^ move left to 1
B1111111XXX0YYYBBB... mark as X and move right to Y
^
B1111111XXX0YYYBBB... move one step left. looking at 0; b < a
^
B11111110000111BBB...
^ change Xs to 0s and Ys to 1s; start over.
(above process repeats two more times)
B10000000000111BBB...
^ erased 3x 1s from a 3x times
B10000000000111BBB...
^ move right to blank
B10000000000111BBB...
^ move one step left. looking at last 1 in b
B1000000000011YBBB...
^ mark as Y and move left to 0.
B1000000000011YBBB...
^ move left to 1
BX000000000011YBBB...
^ mark as X and move right to Y
BX000000000011YBBB...
^ move one step left. looking at last 1 in b.
BX00000000001YYBBB...
^ mark as Y and move left to 0
BX00000000001YYBBB...
^ move left to blank. a < b.
B1BBBBBBBBBBBBBBBB...
^ change Xs to 1s and 0s, 1s, Ys to blank. halt-accept
相關問題
- 1. (a/b)mod n爲大數?
- 2. 圖靈機MOD功能
- 3. 圖靈機:取兩個數字的mod?
- 4. (a mod 2 * x) - (a mod x)
- 5. python a = b b = c函數ETC
- 6. 上圖靈機
- 7. 使deepEquals(a,b)函數無===
- 8. 輸入(a + b)** 2,輸出a * a + a * b + b * a + b * b
- 9. 說到函數依賴時,A→B與B→A是否相同?
- 10. PHP函數,將'a,b'轉換爲'a','b''
- 11. 函數f(a b)= b(a)有一個共同的名字嗎?
- 12. Python a,b = b,a + b
- 13. 測試非整數是否在範圍[a,b) - 或[a,b],(a,b),(a,b)
- 14. 將函數a中創建的變量傳遞給函數b當函數b位於函數a中時
- 15. 從{a-b,b-c,c-a}改變爲{(a,b),(b,c),(c,a)}?
- 16. 混合兩個矢量:[a a]和[b b] to [a b a b]
- 17. 類型參數(F:((A,B))⇒B)(隱式CMP:訂貨[B]):(A,B)
- 18. 設計圖靈機
- 19. A模B,A和B是非常大的數字
- 20. 從視圖中調用視圖B中的jQuery函數A
- 21. 函數A調用調用函數A的函數B,你稱之爲什麼?
- 22. A→B,B→A類協會
- 23. (A && B)與(A和B)
- 24. GROUP BY(A,B)和(B,A)
- 25. jquery函數(a,b)需要說明
- 26. 函數(a,b)的值是什麼?
- 27. PHP變換陣列'a','b','c'到'a/b/c','a/b','a'
- 28. 如何寫一個函數A調用函數B,函數B調用函數A沒有完成函數A,無限循環呢?
- 29. C++:a-power b模數k
- 30. 功能找到a^b的餘數,其中a,b是正整數
太好了!謝謝! – simone