Totient Calculator

Euler's Totient Calculator (phi function)

Determine the count of numbers up to n that are relatively prime to n.

Result:

What is Euler's Totient Function?

Euler's totient function, denoted as φ(n) (phi), is a fundamental concept in number theory. It counts the number of positive integers less than or equal to n that are coprime (relatively prime) to n. Two numbers are coprime if their greatest common divisor (GCD) is exactly 1.

How the Calculation Works

The standard formula for Euler's totient function uses the prime factorization of n. If n has distinct prime factors p1, p2, …, pk, the formula is:

φ(n) = n × (1 – 1/p1) × (1 – 1/p2) × … × (1 – 1/pk)

Practical Examples

  • Example 1: n = 9. The numbers less than 9 are 1, 2, 3, 4, 5, 6, 7, 8. The numbers coprime to 9 are {1, 2, 4, 5, 7, 8}. Therefore, φ(9) = 6.
  • Example 2: n = 13 (Prime Number). For any prime number p, all numbers less than p are coprime to it. Thus, φ(13) = 12 (or p-1).
  • Example 3: n = 10. Factors are 2 and 5. Formula: 10 × (1 – 1/2) × (1 – 1/5) = 10 × 0.5 × 0.8 = 4. The set is {1, 3, 7, 9}.

Applications in Cryptography

Euler's totient function is the backbone of modern digital security, specifically the RSA encryption algorithm. In RSA, φ(n) is used to calculate the private key from the public key, relying on the extreme difficulty of factoring very large composite numbers.

function calculateTotient() { var inputVal = document.getElementById("totientInput").value; var resultDiv = document.getElementById("totientOutput"); var wrapper = document.getElementById("totientResultWrapper"); var explanation = document.getElementById("totientExplanation"); var n = parseInt(inputVal); if (isNaN(n) || n < 1) { alert("Please enter a positive integer greater than or equal to 1."); return; } var result = n; var tempN = n; // Euler's Product Formula Logic for (var i = 2; i * i 1, then tempN is the last prime factor if (tempN > 1) { result = result * (1 – (1 / tempN)); } var finalResult = Math.round(result); resultDiv.innerHTML = finalResult; explanation.innerHTML = "There are " + finalResult + " integers between 1 and " + n + " that share no common factors with " + n + " (excluding 1)."; wrapper.style.display = "block"; }

Leave a Reply

Your email address will not be published. Required fields are marked *