How to resolve the algorithm Deceptive numbers step by step in the Wren programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Deceptive numbers step by step in the Wren 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 Wren programming language
Source code in the wren programming language
/* Deceptive_numbers.wren */
import "./gmp" for Mpz
import "./math" for Int
var count = 0
var limit = 25
var n = 17
var repunit = Mpz.from(1111111111111111)
var deceptive = []
while (count < limit) {
if (!Int.isPrime(n) && n % 3 != 0 && n % 5 != 0) {
if (repunit.isDivisibleUi(n)) {
deceptive.add(n)
count = count + 1
}
}
n = n + 2
repunit.mul(100).add(11)
}
System.print("The first %(limit) deceptive numbers are:")
System.print(deceptive)
import "./math" for Int
var count = 0
var limit = 25 // or 62
var n = 49
var deceptive = []
while (count < limit) {
if (!Int.isPrime(n) && n % 3 != 0 && n % 5 != 0 && Int.modPow(10, n-1, n) == 1) {
deceptive.add(n)
count = count + 1
}
n = n + 2
}
System.print("The first %(limit) deceptive numbers are:")
System.print(deceptive)
You may also check:How to resolve the algorithm Ruth-Aaron numbers step by step in the Haskell programming language
You may also check:How to resolve the algorithm Sierpinski triangle step by step in the TI-83 BASIC programming language
You may also check:How to resolve the algorithm Non-decimal radices/Output step by step in the AutoHotkey programming language
You may also check:How to resolve the algorithm Guess the number/With feedback step by step in the Caché ObjectScript programming language
You may also check:How to resolve the algorithm Hello world/Text step by step in the xEec programming language