1 / 7

質數 (Prime) 相關問題 (III) — 如何找出相對大的質數

質數 (Prime) 相關問題 (III) — 如何找出相對大的質數. Date: May 27, 2009 Introducer: Hsing-Yen Ann. 問題. 9,99 9 ,000,001 到 10,00 0 ,000,000 [10 10 -10 6 +1, 10 10 ] 這一百萬個數之間, 哪些數是質數? 使用 Sieve of Eratosthenes ( 篩法 ) ? 或者使用暴力法? Time 與 Space 均無法滿足。 解法: Segmented Sieve.

Download Presentation

質數 (Prime) 相關問題 (III) — 如何找出相對大的質數

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 質數(Prime)相關問題 (III)— 如何找出相對大的質數 Date: May 27, 2009 Introducer: Hsing-Yen Ann

  2. 問題 • 9,999,000,001 到 10,000,000,000 [1010-106+1, 1010] 這一百萬個數之間,哪些數是質數? • 使用 Sieve of Eratosthenes (篩法)?或者使用暴力法?Time 與 Space 均無法滿足。 • 解法:Segmented Sieve

  3. Segmented Sieve of Eratosthenes (1/4) • [1010-106+1, 1010] 之間,哪些數是質數? • 先用 Sieve of Eratosthenes 計算出[1, 105] 之間的質數 P = {2, 3, 5, 7, 11, 13, 17, 19, ..., 9967, 9973}這些是所有可能的因數 • 建立一個 boolean array isPrime[106],用來表示[1010-106+1, 1010] 之間的數,起始值均設為 true • 對於 P 中的每個質數 p,將 p 位於 [1010-106+1, 1010] 之間的倍數設定為 false

  4. Segmented Sieve of Eratosthenes (2/4) • p=2

  5. Segmented Sieve of Eratosthenes (3/4) • p=3

  6. Segmented Sieve of Eratosthenes (4/4) • p=5

  7. 結論 • [1010-106+1, 1010] 之間,哪些數是質數? • {9999000001, 9999000029, 9999000047, 9999000083, ..., 9999999967}共 43453個質數 • 令範圍為[L, U],且令 D=U-L,則需要時間為:

More Related