How to resolve the algorithm Deceptive numbers step by step in the Rust programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Deceptive numbers step by step in the Rust programming language

Table of Contents

Problem Statement

Repunits are numbers that consist entirely of repetitions of the digit one (unity). The notation Rn symbolizes the repunit made up of n ones. Every prime p larger than 5, evenly divides the repunit Rp-1.

The repunit R6 is evenly divisible by 7. 111111 / 7 = 15873 The repunit R42 is evenly divisible by 43. 111111111111111111111111111111111111111111 / 43 = 2583979328165374677002583979328165374677 And so on.

There are composite numbers that also have this same property. They are often referred to as deceptive non-primes or deceptive numbers.

The repunit R90 is evenly divisible by the composite number 91 (=7*13).

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Deceptive numbers step by step in the Rust programming language

Source code in the rust programming language

// [dependencies]
// primal = "0.3"
// rug = "1.15.0"

fn main() {
    println!("First 100 deceptive numbers:");
    use rug::Integer;
    let mut repunit = Integer::from(11);
    let mut n: u32 = 3;
    let mut count = 0;
    while count != 100 {
        if n % 3 != 0 && n % 5 != 0 && !primal::is_prime(n as u64) && repunit.is_divisible_u(n) {
            print!("{:6}", n);
            count += 1;
            if count % 10 == 0 {
                println!();
            } else {
                print!(" ");
            }
        }
        n += 2;
        repunit *= 100;
        repunit += 11;
    }
}


  

You may also check:How to resolve the algorithm Meissel–Mertens constant step by step in the Java programming language
You may also check:How to resolve the algorithm Water collected between towers step by step in the M2000 Interpreter programming language
You may also check:How to resolve the algorithm Abelian sandpile model/Identity step by step in the ALGOL 68 programming language
You may also check:How to resolve the algorithm Cramer's rule step by step in the Prolog programming language
You may also check:How to resolve the algorithm Pascal's triangle/Puzzle step by step in the F# programming language