How to resolve the algorithm Giuga numbers step by step in the AWK programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Giuga numbers step by step in the AWK programming language
Table of Contents
Problem Statement
A Giuga number is a composite number n which is such that each of its distinct prime factors f divide (n/f - 1) exactly. All known Giuga numbers are even though it is not known for certain that there are no odd examples. 30 is a Giuga number because its distinct prime factors are 2, 3 and 5 and:
Determine and show here the first four Giuga numbers. Determine the fifth Giuga number and any more you have the patience for.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Giuga numbers step by step in the AWK programming language
Source code in the awk programming language
# syntax: GAWK -f GIUGA_NUMBER.AWK
BEGIN {
n = 3
stop = 4
printf("Giuga numbers 1-%d:",stop)
while (count < stop) {
if (is_giuga(n)) {
count++
printf(" %d",n)
}
n++
}
printf("\n")
exit(0)
}
function is_giuga(m, f,l,n) {
n = m
f = 2
l = sqrt(n)
while (1) {
if (n % f == 0) {
if (((m / f) - 1) % f != 0) { return(0) }
n /= f
if (f > n) { return(1) }
}
else {
if (++f > l) { return(0) }
}
}
}
You may also check:How to resolve the algorithm Read a file character by character/UTF8 step by step in the AutoHotkey programming language
You may also check:How to resolve the algorithm Summarize primes step by step in the 11l programming language
You may also check:How to resolve the algorithm Combinations step by step in the Acornsoft Lisp programming language
You may also check:How to resolve the algorithm Abbreviations, easy step by step in the OCaml programming language
You may also check:How to resolve the algorithm Copy stdin to stdout step by step in the OCaml programming language