How to resolve the algorithm Pairs with common factors step by step in the EasyLang programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Pairs with common factors step by step in the EasyLang programming language

Table of Contents

Problem Statement

Generate the sequence where each term n is the count of the pairs (x,y) with 1 < x < y <= n, that have at least one common prime factor.

For instance, when n = 9, examine the pairs: Find all of the pairs that have at least one common prime factor: and count them:

Terms may be found directly using the formula: where 𝚽() is Phi; the Euler totient function.

For the term a(p), if p is prime, then a(p) is equal to the previous term.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Pairs with common factors step by step in the EasyLang programming language

Source code in the easylang programming language

func isprim num .
   if i < 2
      return 0
   .
   i = 2
   while i <= sqrt num
      if num mod i = 0
         return 0
      .
      i += 1
   .
   return 1
.
func totient n .
   tot = n
   i = 2
   while i * i <= n
      if n mod i = 0
         repeat
            n /= i
            until n mod i <> 0
         .
         tot -= tot / i
      .
      if i = 2
         i = 1
      .
      i += 2
   .
   if n > 1
      tot -= tot / n
   .
   return tot
.
write "1-100:"
for n = 1 to 1000
   sumPhi += totient n
   if isprim n = 1
      a = ap
   else
      a = n * (n - 1) / 2 + 1 - sumPhi
   .
   if n <= 100
      write " " & a
   .
   ap = a
.
print ""
print "1000: " & a

  

You may also check:How to resolve the algorithm Perfect numbers step by step in the CoffeeScript programming language
You may also check:How to resolve the algorithm URL encoding step by step in the Nim programming language
You may also check:How to resolve the algorithm Koch curve step by step in the Raku programming language
You may also check:How to resolve the algorithm Tropical algebra overloading step by step in the RPL programming language
You may also check:How to resolve the algorithm Loops/Do-while step by step in the Vala programming language