How many numbers below N are coprimes to N?
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.
In mathematics, particularly number theory, one often encounters the concept of coprime numbers. Two integers are said to be coprime, or relatively prime, if they share no common positive divisors other than 1. When examining integers below a certain number, , a common query arises: how many of these integers are coprime to ? This question is answered using a well-established mathematical function known as Euler's Totient Function, denoted as .
Euler's Totient Function
Euler’s Totient Function, , gives the count of integers up to that are coprime to . For example, if , the numbers 1, 3, 7, and 9 are coprime to 10, so .
The Mathematical Formula
If is expressed as a product of distinct prime factors, , the totient function can be determined through the formula:
Where the prime factors are distinct prime numbers dividing .
Example Calculation
Let's find :
- Prime Factorization: First, find the prime factors of 36: .
- Apply the Formula:
Thus, there are 12 numbers less than 36 that are coprime to 36.
Properties of Euler's Totient Function
• Multiplicative Nature: If and are coprime, then . • For Prime Numbers: If is a prime, because every number less than is coprime to . • For Powers of a Prime: If is a prime and is a positive integer, .
Practical Applications
Euler's Totient function is pivotal in several domains:
• Cryptography: It's used in the RSA algorithm for generating public and private keys. In RSA, computing where is a product of two large primes is the basis for determining the encryption and decryption keys.
• Combinatorial Counting: The function counts the number of residue classes modulo a number that are invertible, which is crucial in various enumeration problems in number theory.
Example Table of Totient Function Values
Here's a small table to summarize Euler's Totient function values for integers from 1 to 10:
| Prime Factors | Coprime Numbers | ||
| 1 | - | 1 | 1 |
| 2 | 2 | 1 | 1 |
| 3 | 3 | 2 | 1, 2 |
| 4 | 2 | 1, 3 | |
| 5 | 5 | 4 | 1, 2, 3, 4 |
| 6 | 2, 3 | 2 | 1, 5 |
| 7 | 7 | 6 | 1, 2, 3, 4, 5, 6 |
| 8 | 4 | 1, 3, 5, 7 | |
| 9 | 6 | 1, 2, 4, 5, 7, 8 | |
| 10 | 2, 5 | 4 | 1, 3, 7, 9 |
Conclusion
Euler's Totient function serves as a bridge into the intricacies of number theory, deepening our understanding of properties like coprimality and modular arithmetic. It embodies the elegance of mathematical abstraction while also offering tangible applications in fields such as cryptography. Understanding the distribution and nature of numbers in relation to their coprimes empowers mathematicians and computer scientists alike to construct solutions to complex problems both theoretical and practical.
Related reading
- How many palindromes can be formed by selections of characters from a string?
- How much do two rectangles overlap?
- How predict_proba in sklearn produces two columns? what are their significance?
- How to build a Language model using LSTM that assigns probability of occurence for a given sentence
- How to calculate a partial Area Under the Curve AUC
- How to calculate a standard deviation array
- How to calculate an angle from three points?
- How to calculate Ebk of networks with Python?

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.