George cantor named mathematician gave a proof that set of rational numbers is enumerable. We don’t have to proof it over here rather we have to determine the Nth term in the set of rational numbers.
Input : N = 8 Output : 2/3 Input : N = 15 Output : 1/5 See image for reference of counting.
The set of rational numbers goes like the below image :
Here the first term is 1/1, second term is 1/2, third term is 2/1, fourth term is 3/1, fifth term is 2/2, sixth term is 1/3 so on……
1. View this as a matrix(2-D array) with rows from 1 to n and columns from 1 to n.
2. rows/columns will give the rational numbers.
3. Observe the pattern from the above image it will be clear how to traverse through the matrix i.e diagonally from left to right upwards and then from right to left downwards till we reach the Nth position.
4. There are 4 regular repeating pattern
One going horizontal one times when i = 1
Then moving downwards horizontally untill j = 1
Then moving verticals ones when j = 1
Then moving diagonal upwards until i = 1
5. After each iteration move to next number to keep counting its position using counter k, then compare it with N
N-th term : 1/5
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Nth term where K+1th term is product of Kth term with difference of max and min digit of Kth term
- Ternary representation of Cantor set
- Find the Nth term of the series where each term f[i] = f[i - 1] - f[i - 2]
- Find Nth term of the series where each term differs by 6 and 2 alternately
- Nth term of a sequence formed by sum of current term with product of its largest and smallest digit
- First term from given Nth term of the equation F(N) = (2 * F(N - 1)) % 10^9 + 7
- Nth term of given recurrence relation having each term equal to the product of previous K terms
- Program to print tetrahedral numbers upto Nth term
- Program to print pentatope numbers upto Nth term
- Find the Nth term of the Zumkeller Numbers
- Sum of series till N-th term whose i-th term is i^k - (i-1)^k
- Count sequences of length K having each term divisible by its preceding term
- Find max of two Rational numbers
- Find LCM of rational numbers
- HCF of array of fractions (or rational numbers)
- Algorithm to generate positive rational numbers
- Reducing Equations to Simpler Form - Rational Numbers | Class 8 Maths
- Program to print the sum of the given nth term
- Program to get the Sum of series: 1 - x^2/2! + x^4/4! -.... upto nth term
- Finding nth term of any Polynomial Sequence
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : jit_t