How to resolve the algorithm Totient function step by step in the Draco programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Totient function step by step in the Draco programming language
Table of Contents
Problem Statement
The totient function is also known as:
The totient function:
If the totient number (for N) is one less than N, then N is prime.
Create a totient function and: Show all output here.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Totient function step by step in the Draco programming language
Source code in the draco programming language
proc totient(word n) word:
word tot, i;
tot := n;
i := 2;
while i*i <= n do
if n%i = 0 then
while n%i = 0 do n := n/i od;
tot := tot - tot/i
fi;
if i=2 then i:=1 fi;
i := i+2
od;
if n>1 then
tot - tot/n
else
tot
fi
corp
proc main() void:
word count, n, tot;
bool prime;
count := 0;
writeln(" N Totient Prime");
for n from 1 upto 25 do
tot := totient(n);
prime := n-1 = tot;
if prime then count := count+1 fi;
writeln(n:2, " ", tot:7, " ", if prime then " Yes" else " No" fi)
od;
writeln("Number of primes up to ",25:6,": ",count:4);
for n from 25 upto 10000 do
if totient(n) = n-1 then count := count+1 fi;
if n=100 or n=1000 or n=10000 then
writeln("Number of primes up to ",n:6,": ",count:4)
fi
od
corp
You may also check:How to resolve the algorithm Variable-length quantity step by step in the C# programming language
You may also check:How to resolve the algorithm Array concatenation step by step in the Wart programming language
You may also check:How to resolve the algorithm Loops/Nested step by step in the Ring programming language
You may also check:How to resolve the algorithm Read entire file step by step in the NewLISP programming language
You may also check:How to resolve the algorithm Jacobi symbol step by step in the Sidef programming language