pub fn sieve_nth(n: u32) -> Option<u32> {
        if n == 0 {
            return None;
        }

        let mut primes: Vec<u32> = vec![2];
        let mut counter = 3;

        while (primes.len() as u32) < n {
            if primes
                .iter()
                .filter(|&x| counter % x == 0)
                .collect::<Vec<_>>()
                .is_empty()
            {
                write_colors::write_green(format!("{}", counter).as_str());
                write_colors::write_white(format!(" is prime\n").as_str());
                primes.push(counter);
            }
            write_colors::write_red(format!("{}", counter + 1).as_str());
            write_colors::write_white(format!(" is not prime\n").as_str());
            counter += 2
        }

        if let Some(n) = primes.last() {
            Some(*n)
        } else {
            None
        }
    }
/// Calculate the nth prime using the Sieve of Eratosthenes
Calculate the nth prime using the Sieve of Eratosthenes
Calculate the nth prime using the Sieve of Eratosthenes
pub fn sieve_nth(n: u32) -> Option<u32> {
        if n == 0 {
            return None;
        }
        let mut primes: Vec<u32> = vec![2];
        let mut counter = 3;
        while (primes.len() as u32) < n {
            if primes
                .iter()
                .filter(|&x| counter % x == 0)
                .collect::<Vec<_>>()
                .is_empty()
            {
                write_colors::write_green(format!("{}", counter).as_str());
                write_colors::write_white(format!(" is prime\n").as_str());
                primes.push(counter);
            }
            write_colors::write_red(format!("{}", counter + 1).as_str());
            write_colors::write_white(format!(" is not prime\n").as_str());
            counter += 2
        }
        if let Some(n) = primes.last() {
            Some(*n)
        } else {
            None
        }
    }
pub fn sieve_nth ( n : u32 ) -> Option < u32 > { if n == 0 { return None ; } let mut primes : Vec < u32 > = vec ! [ 2 ] ; let mut counter = 3 ; while ( primes . len ( ) as u32 ) < n { if primes . iter ( ) . filter ( | & x | counter % x == 0 ) . collect :: < Vec < _ > > ( ) . is_empty ( ) { write_colors :: write_green ( format ! ( " " counter ) . as_str ( ) ) ; write_colors :: write_white ( format ! ( " \n " ) . as_str ( ) ) ; primes . push ( counter ) ; } write_colors :: write_red ( format ! ( " " counter 1 ) . as_str ( ) ) ; write_colors :: write_white ( format ! ( " \n " ) . as_str ( ) ) ; counter += 2 } if let Some ( n ) = primes . last ( ) { Some ( * n ) } else { None } }
Calculate the nth prime using the Sieve of Eratosthenes
Calculate the nth prime using the Sieve of Eratosthenes
n
u32
n
u32