Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
#include
#include
#include
#include
#define TRUE 1 #define FALSE 0 int main(int argc, char* argv[]) { int n, m, lim; double s; char* nums; char input[255]; clock_t start, stop; if (argc == 2) lim = atoi(argv[1]); else { printf("Enter a limit for this search (empty for default): "); gets(input); if (input[0]) lim = atoi(input); else lim = 100000000; } s = sqrt(lim); start = clock(); nums = (char *)calloc(lim + 1, sizeof(char)); for (n = 2; n < s; n++) { if (nums[n] == FALSE) { m = n * n; while (m <= lim) { nums[m] = TRUE; m += n; } } } stop = clock(); printf("It took %f seconds.\n", (double)(stop - start) / 1000); printf("Do you want to list the results, count total, or do nothing (L/C/N)? "); gets(input); if (input[0] == 'L' || input[0] == 'l' || input[0] == 'C' || input[0] == 'c') { m = 0; for (n = 2; n < lim; n++) { if (nums[n] == FALSE) { if (input[0] == 'L' || input[0] == 'l') printf("%d\n", n); m++; } } printf("Total primes = %d\n\n", m); printf("Press ENTER to exit. . . "); getchar(); } free(nums); return 0; }
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)