fn mark_false_if_not_prime(limit: usize, sieve: &mut Vec<bool>) -> io::Result<()> {
        sieve[0] = false;

        if limit >= 1 {
            sieve[1] = false;
        }

        // Perform a trial division
        write_colors::write_white("")?;
        println!("Sieve of Eratosthenes");
        println!("performing a trial division...\n");

        for n in 2..=limit {
            if sieve[n] {
                let mut x = n * n;
                write_colors::write_green(format!("{}", n).as_str())?;
                write_colors::write_white(format!(" is prime\n").as_str())?;
                while x <= limit {
                    write_colors::write_green(format!("{} ", n).as_str())?;
                    write_colors::write_white(format!("+ ").as_str())?;
                    write_colors::write_red(format!("{} ", x).as_str())?;
                    write_colors::write_white(format!("= ").as_str())?;
                    write_colors::write_red(format!("{}\n", n + x).as_str())?;
                    sieve[x] = false;
                    x += n;
                }
                write_colors::write_white("\n")?;
            }
        }
        Ok(())
    }
/// Mark all non prime indices as false in a boolean vevtor.
Mark all non prime indices as false in a boolean vevtor.
Mark all non prime indices as false in a boolean vevtor .
fn mark_false_if_not_prime(limit: usize, sieve: &mut Vec<bool>) -> io::Result<()> {
        sieve[0] = false;
        if limit >= 1 {
            sieve[1] = false;
        }
        // Perform a trial division
        write_colors::write_white("")?;
        println!("Sieve of Eratosthenes");
        println!("performing a trial division...\n");
        for n in 2..=limit {
            if sieve[n] {
                let mut x = n * n;
                write_colors::write_green(format!("{}", n).as_str())?;
                write_colors::write_white(format!(" is prime\n").as_str())?;
                while x <= limit {
                    write_colors::write_green(format!("{} ", n).as_str())?;
                    write_colors::write_white(format!("+ ").as_str())?;
                    write_colors::write_red(format!("{} ", x).as_str())?;
                    write_colors::write_white(format!("= ").as_str())?;
                    write_colors::write_red(format!("{}\n", n + x).as_str())?;
                    sieve[x] = false;
                    x += n;
                }
                write_colors::write_white("\n")?;
            }
        }
        Ok(())
    }
fn mark_false_if_not_prime ( limit : usize , sieve : & mut Vec < bool > ) -> io :: Result < ( ) > { sieve [ 0 ] = false ; if limit >= 1 { sieve [ 1 ] = false ; } // Perform a trial division write_colors :: write_white ( " " ) ? ; println ! ( " " ) ; println ! ( " \n " ) ; for n in 2 ..= limit { if sieve [ n ] { let mut x = n * n ; write_colors :: write_green ( format ! ( " " n ) . as_str ( ) ) ? ; write_colors :: write_white ( format ! ( " \n " ) . as_str ( ) ) ? ; while x <= limit { write_colors :: write_green ( format ! ( " " n ) . as_str ( ) ) ? ; write_colors :: write_white ( format ! ( " " ) . as_str ( ) ) ? ; write_colors :: write_red ( format ! ( " " x ) . as_str ( ) ) ? ; write_colors :: write_white ( format ! ( " " ) . as_str ( ) ) ? ; write_colors :: write_red ( format ! ( " \n " n x ) . as_str ( ) ) ? ; sieve [ x ] = false ; x += n ; } write_colors :: write_white ( " \n " ) ? ; } } Ok ( ( ) ) }
Mark all non prime indices as false in a boolean vevtor.
Mark all non prime indices as false in a boolean vevtor .
limit
usize
sieve
&mut Vec<bool>
limit
usize
sieve
&mut Vec<bool>