![文稿說明講稿1811sol_第1頁](http://file4.renrendoc.com/view/3db59e54ef83bcd13343316d353aab00/3db59e54ef83bcd13343316d353aab001.gif)
![文稿說明講稿1811sol_第2頁](http://file4.renrendoc.com/view/3db59e54ef83bcd13343316d353aab00/3db59e54ef83bcd13343316d353aab002.gif)
![文稿說明講稿1811sol_第3頁](http://file4.renrendoc.com/view/3db59e54ef83bcd13343316d353aab00/3db59e54ef83bcd13343316d353aab003.gif)
![文稿說明講稿1811sol_第4頁](http://file4.renrendoc.com/view/3db59e54ef83bcd13343316d353aab00/3db59e54ef83bcd13343316d353aab004.gif)
![文稿說明講稿1811sol_第5頁](http://file4.renrendoc.com/view/3db59e54ef83bcd13343316d353aab00/3db59e54ef83bcd13343316d353aab005.gif)
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認(rèn)領(lǐng)
文檔簡介
1、A Solution toPOJ1811 Prime TestSTYCProblem DescriptionGiven an integer N which satisfies the relation 2 N 1 that has no positive integer divisors other than 1 and p itself.Framework of the SolutionDetermine whether the given N is prime or not.If N is prime, print “Prime” and exit.Factorize N for its
2、 smallest prime factor.The Brute-force WayTrial DivisionIf N is even, then 2 is its smallest prime factor.Try dividing N by every odd number k between 2 and N1/2. The smallest k by which N is divisible is the smallest prime factor of N. If such k does not exist, then N is prime.Complexity: O(N1/2) f
3、or time, O(1) for spaceModified Brute-forceConstruct a table that stores all prime numbers not greater than N1/2. Try dividing N only by prime numbers.Complexity: O(N1/2logN) for time, O(N1/2) for space using Sieve of EratosthenesEstimation of space consumption: 226 bits = 223 bytes = 8,192 kilobyte
4、sMuch time is used in the process of sievingModified Brute-force 2Embed a table of prime numbers smaller than Nmax1/4 into the source. Extend the table to N1/2 by runtime calculation.Complexity: O(N3/4/logN) for time, O(N1/2/logN) for spaceEstimation of time consumption: Finding all 7,603,553 primes
5、 smaller than 227 takes approx. 1.32 x 1011 divisions or 73 minutes on a Pentium 1.5 GHz.Brute-force with TrickStart from N1/2 rather than 2. Do factorization recursively once a factor is found.Efficient in handling N = pq where p and q relatively close to each other.POJ accepts this! - westevers so
6、lutionBrute-force with Trick 2Wheel FactorizationTest whether N is a multiple of 2, 3 or 5. If it is, the problem has been solved.If not, do trial division using only integers which are not multiples of 2, 3, and 5.Saves 7/15 of work.Key Concepts (cont.)Prime factorization algorithms: Algorithms dev
7、ised for determining the prime factors of a given numberPrimality tests: Tests to determine whether or not a given number is prime, as opposed to actually posing the number into its constituent prime factorsPrimality TestsDeterministic: Adleman-Pomerance-Rumely Primality Test, Elliptic Curve Primali
8、ty ProvingProbabilistic: Rabin-Miller Strong Pseudoprime TestRabin-MillerStrong Pseudoprime TestGiven an odd integer N, let N = 2rs + 1 with s odd. Then choose a random integer a between 1 and N - 1. If as = 1 (mod N) or a2j s = -1 (mod N) for some j between 0 and r - 1, then N passes the test. A pr
9、ime will pass the test for all a.Rabin-MillerStrong Pseudoprime TestRequires no more than (1 + o(1)logN multiplications (mod N).A number which passes the test is not necessarily prime. But a composite number passes the test for at most 1/4 of the possible bases a.If n multiple independent tests are
10、performed on a composite number, the probability that it passes each test is 1/4n or less.Rabin-MillerStrong Pseudoprime TestSmallest composite numbers passing the RMSPT using the first k primes as bases: 2,047; 1,373,653; 25,326,001; 3,215,031,751; 2,152,302,898,747; 3,474,749,660,383; 341,550,071,
11、728,321, 341,550,071,728,321; at most 41,234,316,135,705,689,041341,550,071,728,321 = 244.957, 41,234,316,135,705,689,041 = 265.160Tests show that randomized bases may fail sometimes.Pseudocode of RMSPT (Sprache)function powermod(a, s, n)p := 1b := awhile s 0if s & 1 = 1 then p := p * b % nb := b *
12、b % ns := s 1Pseudocode of RMSPT (cont.)function rabin-miller(n)if n 2 AND powermod(2, n - 1, n) != 1 then return FALSEif n 3 AND powermod(3, n - 1, n) != 1 then return FALSEif n 5 AND powermod(5, n - 1, n) != 1 then return FALSEif n 7 AND powermod(7, n - 1, n) != 1 then return FALSEif n 11 AND powe
13、rmod(11, n - 1, n) != 1 then return FALSEif n 13 AND powermod(13, n - 1, n) != 1 then return FALSEif n 17 AND powermod(17, n - 1, n) != 1 then return FALSEif n 19 AND powermod(19, n - 1, n) != 1 then return FALSEif n 23 AND powermod(23, n - 1, n) != 1 then return FALSEreturn TRUEPrime Factorization
14、AlgorithmsContinued Fraction Algorithm, Lenstra Elliptic Curve Method, Number Field Sieve, Pollard Rho Method, Quadratic Sieve, Trial DivisionPollard RhoFactorization MethodAlso known as Pollard Monte Carlo factorization method.Runs at O(p1/2) where p is the largest prime factor of the number to be
15、factored.Two aspects to this method: iteration and cycle detection.Pollard RhoFactorization MethodIteration:Iterate the formula xn+1 = xn2 + a (mod N). Almost any polynomial formula (two exceptions being xn2 and xn2 - 2) for any initial value x0 will produce a sequence of numbers that eventually fal
16、ls into a cycle.Pollard RhoFactorization MethodCycle detection:Keep one running copy of xi. If i is power of 2, let y = xi, and at each step, compute GCD(|xi - y|, N). If the result is neither 1 nor N, then a cycle is detected and GCD(|xi - y|, N) is a factor (not necessarily prime) of N. If the res
17、ult is N, the method fails, choose another a and redo iteration.Pseudocode of RRFM (Sprache)function pollard-rho(n)doa := random()while a = 0 OR a = -2y := xk := 2i := 1Pseudocode of RRFM (cont.)while TRUEi := i + 1x := (x * x + a) % ne := abs(x - y)d := GCD(e, n)if d != 1 AND d != n then return del
18、se if i = k theny := xk := k b) in PRFM: Following properties of GCD helps avoiding divisions:If a = b, then GCD(a, b) = a.GCD(a, b) = 2 * GCD(a/2, b/2) with both a and b even.GCD(a, b) = GCD(a/2, b) with a even but b odd.GCD(a, b) = GCD(a - b, b) with both a and b odd.Time complexity: O(logb)Notes
19、on Implementation (cont.)Combination with brute-force algorithms: Embed a prime table. Do brute-force trial division for small divisors.Minor optimizations: Use 32-bit integer division instead of the 64-bit version when possibleActual Timing PerformancePlatform: Windows XP SP1 on a Pentium M 1.5 GHzAlgorithms tested: Adapted versions of westevers, TNs, lhs and zsuyrls solutions and my later fixed versionTiming method: Process user time returned by the GetProcessTimes Windows APIActual Timing PerformanceTest data: Original data set on POJ, two pseudorandom data sets generated by Mathem
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 電力行業(yè)助理的工作職責(zé)簡述
- 高校人才培養(yǎng)方案的更新
- 2025年全球及中國石油和天然氣行業(yè)用有機緩蝕劑行業(yè)頭部企業(yè)市場占有率及排名調(diào)研報告
- 2025-2030全球桶形立銑刀行業(yè)調(diào)研及趨勢分析報告
- 2025年全球及中國醫(yī)療推車液晶顯示器行業(yè)頭部企業(yè)市場占有率及排名調(diào)研報告
- 2025-2030全球輪胎式破碎機行業(yè)調(diào)研及趨勢分析報告
- 2025年全球及中國劇場動作自動化設(shè)備行業(yè)頭部企業(yè)市場占有率及排名調(diào)研報告
- 2025年全球及中國單線金剛石線切割機行業(yè)頭部企業(yè)市場占有率及排名調(diào)研報告
- 2025-2030全球履帶調(diào)節(jié)器行業(yè)調(diào)研及趨勢分析報告
- 2025-2030全球防水低光雙筒望遠(yuǎn)鏡行業(yè)調(diào)研及趨勢分析報告
- 安全生產(chǎn)網(wǎng)格員培訓(xùn)
- 小學(xué)數(shù)學(xué)分?jǐn)?shù)四則混合運算300題帶答案
- 林下野雞養(yǎng)殖建設(shè)項目可行性研究報告
- 心肺復(fù)蘇術(shù)課件2024新版
- 2024年內(nèi)蒙古呼和浩特市中考文科綜合試題卷(含答案)
- 大型商場招商招租方案(2篇)
- 會陰擦洗課件
- 2024年交管12123學(xué)法減分考試題庫和答案
- 臨床下肢深靜脈血栓的預(yù)防和護理新進展
- 2024年山東泰安市泰山財金投資集團有限公司招聘筆試參考題庫含答案解析
- 內(nèi)鏡下粘膜剝離術(shù)(ESD)護理要點及健康教育
評論
0/150
提交評論