int main(){ Sieve(); printf("%d\n", p); int i; for (i = 0; i < 60; i++){ if (isprime(i)) printf("%d\n", i); } }
int main() { int i,j,k,l,m,n,t,x,y,blank,test=0; Sieve(); while(scanf("%d",&n) && n) { printf("Case %d: ",++test); for(i=1000;i>=0;i--) if(n==divi[i]) { printf("%d\n",i); break; } if(i==-1) printf("-1\n"); } return 0; }
int main() { int n, i; Sieve(); while(scanf("%d", &n) == 1 && n) { int x, y, flag = 0; for(i = 0; i < Pt; i++) { x = Prime[i], y = n-Prime[i]; if(x > y) break; if(mark[x] == 0 && mark[y] == 0) { printf("%d = %d + %d\n", n, x, y); flag = 1; break; } } if(!flag) puts("Goldbach's conjecture is wrong."); } return 0; }
int main() { int n; Sieve(); scanf("%d", &n); if(IsPrime(n)) { printf("%d\n", 1); } else { char haveTow = 0; for(int i = 0; i < PrimeCnt; ++i) { if(IsPrime(n - Prime[i])) { haveTow = 1; break; } } printf("%d\n", haveTow ? 2 : 3); } return 0; }
int main() { uint32_t PrimeCeiling; printf(" ---Instructions---\n\n"); printf("The Sieve of a Eratosthenes is an algorithm for finding\nprime numbers that is over 2,000 years old. Enter an\ninteger greater than 2 and press enter to return\na list of prime numbers smaller than the one you typed.\n\n"); printf("Give me a number: "); scanf("%u", &PrimeCeiling); while(1) { if(PrimeCeiling < 3) { printf("Number must be 2 greater than 2!\n"); printf("Give me a number: "); scanf("%u", &PrimeCeiling); } else { uint32_t *PrimesList = malloc(PrimeCeiling * sizeof(uint32_t)); if(PrimesList == NULL) { printf("Memory error!\n"); break; } uint32_t PrimeCount = Sieve(PrimeCeiling, PrimesList, PrimeCeiling * sizeof(uint32_t)); PrintIntArray(PrimesList, PrimeCount); printf("\nNumber of primes found was %u.\n", PrimeCount); float PercentPrimes = ((float)PrimeCount / (float)PrimeCeiling) * 100; printf("%.2f%% of numbers between 0 and %u are prime.\n", PercentPrimes, PrimeCeiling); break; } } return 0; }
#include <algorithm> #include <vector> #include "base/digit_manipulation.h" #include "base/number_theory.h" #include "base/task.h" TASK(49) { auto prime_list = Sieve(10*1000); auto new_end = std::remove_if(prime_list.begin(), prime_list.end(), [](int n) { return n < 1000; }); prime_list.erase(new_end, prime_list.end()); std::string result; for (size_t i = 0; i < prime_list.size(); ++i) { for (size_t j = i + 2; j < prime_list.size(); ++j) { int lowest_prime = prime_list[i]; int highest_prime = prime_list[j]; int mid_prime = (lowest_prime + highest_prime) / 2; if (!std::binary_search(prime_list.begin(), prime_list.end(), mid_prime)) { continue; } if (GetDigitSet(lowest_prime) == GetDigitSet(mid_prime) && GetDigitSet(lowest_prime) == GetDigitSet(highest_prime)) { if (lowest_prime == 1487 && mid_prime == 4817 && highest_prime == 8147) { continue; } else { result += std::to_string(lowest_prime);
void cMiniBench::RunTests() { if( TestsToRun[ eAes ] ) { StatusBarUpdate( "Running AES ECB Encypt/Decrypt Tests..." ); cAesBench AesBench; StatusBarUpdate( "Running AES 8kB ECB Encypt/Decrypt Tests..." ); OutputRaw( AesBench.runEncryptBenchmark8KB( true ), "AES ECB Encrypt 8kB score: " ); OutputRaw( AesBench.runDecryptBenchmark8KB( true ), "AES ECB Decrypt 8kB score: " ); StatusBarUpdate( "Running AES 16kB ECB Encypt/Decrypt Tests..." ); OutputRaw( AesBench.runEncryptBenchmark16KB( true ), "AES ECB Encrypt 16kB score: " ); OutputRaw( AesBench.runDecryptBenchmark16KB( true ), "AES ECB Decrypt 16kB score: " ); StatusBarUpdate( "Running AES 32kB ECB Encypt/Decrypt Tests..." ); OutputRaw( AesBench.runEncryptBenchmark32KB( true ), "AES ECB Encrypt 32kB score: " ); OutputRaw( AesBench.runDecryptBenchmark32KB( true ), "AES ECB Decrypt 32kB score: " ); StatusBarUpdate( "Running AES 64kB ECB Encypt/Decrypt Tests..." ); OutputRaw( AesBench.runEncryptBenchmark64KB( true ), "AES ECB Encrypt 64kB score: " ); OutputRaw( AesBench.runDecryptBenchmark64KB( true ), "AES ECB Decrypt 64kB score: " ); StatusBarUpdate( "Running AES 128kB ECB Encypt/Decrypt Tests..." ); OutputRaw( AesBench.runEncryptBenchmark128KB( true ), "AES ECB Encrypt 128kB score: " ); OutputRaw( AesBench.runDecryptBenchmark128KB( true ), "AES ECB Decrypt 128kB score: " ); StatusBarUpdate( "Running AES 256kB ECB Encypt/Decrypt Tests..." ); OutputRaw( AesBench.runEncryptBenchmark256KB( true ), "AES ECB Encrypt 256kB score: " ); OutputRaw( AesBench.runDecryptBenchmark256KB( true ), "AES ECB Decrypt 256kB score: " ); StatusBarUpdate( "Running AES 512kB ECB Encypt/Decrypt Tests..." ); OutputRaw( AesBench.runEncryptBenchmark512KB( true ), "AES ECB Encrypt 512kB score: " ); OutputRaw( AesBench.runDecryptBenchmark512KB( true ), "AES ECB Decrypt 512kB score: " ); StatusBarUpdate( "Running AES 1024kB ECB Encypt/Decrypt Tests..." ); OutputRaw( AesBench.runEncryptBenchmark1024KB( true ), "AES ECB Encrypt 1024kB score: " ); OutputRaw( AesBench.runDecryptBenchmark1024KB( true ), "AES ECB Decrypt 1024kB score: " ); StatusBarUpdate( "Running AES 2048kB ECB Encypt/Decrypt Tests..." ); OutputRaw( AesBench.runEncryptBenchmark2048KB( true ), "AES ECB Encrypt 2048kB score: " ); OutputRaw( AesBench.runDecryptBenchmark2048KB( true ), "AES ECB Decrypt 2048kB score: " ); StatusBarUpdate( "Running AES 4096kB ECB Encypt/Decrypt Tests..." ); OutputRaw( AesBench.runEncryptBenchmark4096KB( true ), "AES ECB Encrypt 4096kB score: " ); OutputRaw( AesBench.runDecryptBenchmark4096KB( true ), "AES ECB Decrypt 4096kB score: " ); StatusBarUpdate( "Running AES 8192kB ECB Encypt/Decrypt Tests..." ); OutputRaw( AesBench.runEncryptBenchmark8192KB( true ), "AES ECB Encrypt 8192kB score: " ); OutputRaw( AesBench.runDecryptBenchmark8192KB( true ), "AES ECB Decrypt 8192kB score: " ); StatusBarUpdate( "Running AES 16384kB ECB Encypt/Decrypt Tests..." ); OutputRaw( AesBench.runEncryptBenchmark16384KB( true ), "AES ECB Encrypt 16384kB score: " ); OutputRaw( AesBench.runDecryptBenchmark16384KB( true ), "AES ECB Decrypt 16384kB score: " ); } if( TestsToRun[ eDhrystone ] ) { StatusBarUpdate( "Running Dhrystone..." ); CDhryApp dhry( 20000000 ); OutputSeconds( dhry.RunTest( 20000000 ), "Dhrystone" ); } if( TestsToRun[ eDoubleArithmetic ] ) { StatusBarUpdate( "Running Double Arithmetic..." ); OutputSeconds( doubleArithmetic( 10000000000.0, 11000000000.0 ), "Double Arithmetic (s): " ); } if( TestsToRun[ eFibonacci ] ) { StatusBarUpdate( "Running Fibonacci( 42 )..." ); cFibTest FibTest( 1 ); OutputSeconds( FibTest.Run(), "Fib(42)" ); } if( TestsToRun[ eFft ] ) { StatusBarUpdate( "Running FFT..." ); cFFT FFT( 1 ); OutputSeconds( FFT.Run(), "FFT" ); } if( TestsToRun[ eFlops ] ) { cFlops lFlops; // addition: StatusBarUpdate( "MFLOPS SP Add..." ); OutputRaw( lFlops.runFpuFloatAddTest(), "MFLOPS (SP add): " ); StatusBarUpdate( "MFLOPS DP Add..." ); OutputRaw( lFlops.runFpuDoubleAddTest(), "MFLOPS (DP add): " ); // multiplication StatusBarUpdate( "MFLOPS SP Mul..." ); OutputRaw( lFlops.runFpuFloatMulTest(), "MFLOPS (SP mul): " ); StatusBarUpdate( "MFLOPS DP Mul..." ); OutputRaw( lFlops.runFpuDoubleMulTest(), "MFLOPS (DP mul): " ); // division: StatusBarUpdate( "MFLOPS SP Div..." ); OutputRaw( lFlops.runFpuFloatDivTest(), "MFLOPS (SP div): " ); StatusBarUpdate( "MFLOPS DP Div..." ); OutputRaw( lFlops.runFpuDoubleDivTest(), "MFLOPS (DP div): " ); // mul-add: StatusBarUpdate( "MFLOPS DP Mul-Add..." ); OutputRaw( lFlops.runFpuDoubleMulAdd3Test(), "MFLOPS (DP mul-add): " ); } if( TestsToRun[ eHeapSort ] ) { StatusBarUpdate( "Running Heap Sort..." ); OutputSeconds( HeapSortTest( 5000000 ), "Heap Sort (s): " ); } if( TestsToRun[ eIntArithmetic ] ) { StatusBarUpdate( "Running Integer Arithmetic..." ); OutputSeconds( intArithmetic( 1000000000 ), "Integer Arithmetic (s): " ); } if( TestsToRun[ eInt64Arithmetic ] ) { StatusBarUpdate( "Running 64-bit Arithmetic..." ); OutputSeconds( longArithmetic( 10000000000LL, 11000000000LL ), "64-bit Arithmetic (s): " ); } if( TestsToRun[ eIntegerMatrixMul ] ) { StatusBarUpdate( "Running Integer Matrix Multiplication..." ); OutputSeconds( IntegerMatrixMultiplication( 1 ), "Integer Matrix Multiplication (s): " ); } if( TestsToRun[ eIO ] ) { StatusBarUpdate( "Running I/O..." ); OutputSeconds( io( 10000000 ), "I/O (s): " ); remove( "DeleteMe_minibench.txt" ); } if( TestsToRun[ eLinpack ] ) { cLinpackTest lLinpack( 1 ); StatusBarUpdate( "Running Linpack rolled..." ); lLinpack.Run(); OutputRaw( lLinpack.GetFlops(), "LinPack rolled (FLOPS): " ); StatusBarUpdate( "Running Linpack unrolled..." ); lLinpack.SetRolling( eUnrolled ); lLinpack.Run(); OutputRaw( lLinpack.GetFlops(), "LinPack unrolled (FLOPS): " ); } if( TestsToRun[ eAllMemoryTests] ) { StatusBarUpdate( "Memory Bandwidth Integer Write (MB/s): " ); OutputRaw( BandwidthIntegerWrite( 2000000 ), "Memory Bandwidth Integer Write (MB/s): " ); StatusBarUpdate( "Memory Bandwidth MemCpy (MB/s): " ); OutputRaw( BandwidthMemCpy( 2000000 ), "Memory Bandwidth MemCpy (MB/s): " ); StatusBarUpdate( "Memory Bandwidth Double Copy (MB/s): " ); OutputRaw( BandwidthDoubleCopy( 2000000 ), "Memory Bandwidth Double Copy (MB/s): " ); } if( TestsToRun[ eRandomAssignment ] ) { StatusBarUpdate( "Memory Latency Random Assignment (MB/s): " ); OutputRaw( RandomAssignment( 2000000 ), "Memory Latency Random Assignment (MB/s): " ); } if( TestsToRun[ ePi ] ) { StatusBarUpdate( "Running Pi( 10,000 )..." ); int i = 0; { i += PiTest( 10000 ); } OutputSeconds( i, "Pi to 10,000 digits (s): " ); } if( TestsToRun[ eQueens ] ) { StatusBarUpdate( "Running Queens..." ); double ldRunTime = 0; cQueensTest Queens( 1 ); ldRunTime = Queens.Run(); /* #pragma omp parallel { num_threads = omp_get_num_threads(); CQueens Queens; #pragma omp atomic ldRunTime += Queens.RunTest(25000); } */ cout << "Queens (seconds per thread): " << ldRunTime << endl; cout << "Number of threads = " << Queens.GetNumberOfThreads() << endl; } if( TestsToRun[ eSha1 ] ) { StatusBarUpdate( "Running SHA1 Tests..." ); cSha1Bench lSha1Bench; if( lSha1Bench.runSha1ValidationTests( true ) ) { OutputSeconds( lSha1Bench.runBenchmark( true ), "SHA1 (s): " ); // OutputRaw( lSha1Bench.getScoreOverall() ); // OutputRaw( lSha1Bench.getScoreForSmallStrings(), "SHA1 small strings: " ); // Sha1Score50KString = lSha1Bench.getScoreFor50kString(); // Sha1Score1MString = lSha1Bench.getScoreFor1MString(); // Sha1Score10MString = lSha1Bench.getScoreFor10MString(); // } // if } else { cerr << "Sha1 validation tests failed!" << endl; StatusBarUpdate( "Sha1 validation tests failed!" ); } // if...else } if( TestsToRun[ eSha256 ] ) { cSha256Bench lSha256Bench; if( lSha256Bench.runSha256ValidationTests( true ) ) { StatusBarUpdate( "Executing SHA-256 timed tests..." ); OutputSeconds( lSha256Bench.runBenchmark( true ), "SHA256 (s): " ); // cerr << "The benchmark took " << TestTime << " milliseconds for all hash tests." << endl; // if( Sha256ScoreOverall < lSha256Bench.getScoreOverall() ) // { // Sha256ScoreOverall = lSha256Bench.getScoreOverall(); // Sha256ScoreSmallStrings = lSha256Bench.getScoreForSmallStrings(); // Sha256Score50KString = lSha256Bench.getScoreFor50kString(); // Sha256Score1MString = lSha256Bench.getScoreFor1MString(); // Sha256Score10MString = lSha256Bench.getScoreFor10MString(); // } // if } else { StatusBarUpdate( "Sha256 validation tests failed!" ); } // if...else } if( TestsToRun[ eSieve ] ) { StatusBarUpdate( "Sieve..." ); OutputSeconds( Sieve( 50000 ), "Sieve (s): " ); } if( TestsToRun[ eStringConcat ] ) { StatusBarUpdate( "String Concatenation..." ); OutputSeconds( StringConcatenation( 40000000 ), "String Concatenation (s): " ); } if( TestsToRun[ eTrig ] ) { StatusBarUpdate( "Running Trig..." ); OutputSeconds( trig( 10000000 ), "Trig (s): " ); } if( TestsToRun[ eWhetstone ] ) { StatusBarUpdate( "Running Whetstone..." ); CWhetApp whet; OutputSeconds( whet.RunTest( 50000 ), "Whetstone (s): " ); } StatusBarUpdate( "All tests finished!" ); }