Skip to main content

Write Program

Write

In Rust, Sieve of Eratosthenes can be written as

rust/src/prime.rs
loading...

Build for Test

Build the program with cargo.
This command generates target/release/main.exe.

build with cargo
cargo build --release

Run and Test

Now, run executable file with an argument like

invoke main function
cd target/release/
main.exe 10000
output
given number = 9973
max prime = 9973
duration [ns] = 1291000

Or, cargo command can directly invoke the program and results in same output.

directly invoke main function
cargo run --release 10000

The following table shows the calculated prime for given "N".

given Nprime
22
33
107
10097
1000997
100009973
10000099991