được lưu trữ ra khỏi danh sách. Đây là một cải tiến đáng kể so với thử nghiệm tất cả các số chia từ 2 lên vào thư mục gốc của một ứng cử viên (một cách mù quáng). Về kết quả? Như hình cho thấy, thời gian chạy thử nghiệm ứng cử viên 10 triệu là giảm từ 22 giây đến 4,7 giây! Đây là một thông mới của số nguyên tố mỗi | 40 Simpor PDF Mei-gerand Split Unregistered Vereion - httpV BOOST_FOREACH biglong prime primes if count 100 std cout prime else if count primeCount-100 std cout n nLast 100 primes n else if count primeCount-100 std cout prime count std cout n system pause return 0 This new version of the primality test replaces the core loop of the findPrimes function. Previously variable testDivisor was incremented until the root of a candidate was reached to test for primality. Now testDivisor is the increment variable in a BOOST_FOREACH loop which pulls previously stored primes out of the list. This is a significant improvement over testing every divisor from 2 up to the root of a candidate blindly . What about the results As Figure shows the runtime for a 10 million candidate test is down from 22 seconds to seconds This is a new throughput of 141 369 primes per second nearly five times faster. Optimizing the Primality Test Odd Candidates There is no need to test even candidates because they will never be prime anyway We can start testing divisors and candidates at 3 rather than 2 and then increment candidates by 2 so that the evens are skipped entirely. We will just have to print out 2 first since it is no longer being tested but that s no big deal. Here is the improved version. This project is called Prime Number Test 3. include include iostream include list include boost Simpo PDF Merge and Split Unregistered Version -Phttp Figure Using primes as divisors improves performance nearly five-fold. include boost include boost declare a 64-bit long integer type typedef unsigned long long biglong const long MILLION 1000000 biglong highestPrime 10 MILLION boost timer timer1 std list biglong primes long findPrimes biglong rangeFirst biglong rangeLast long count 0 biglong candidate rangeFirst if candidate 3 candidate 3 2 while candidate rangeLast bool prime true get divisor from .