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
- 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
- Program to print tetrahedral numbers upto Nth term
- Program to print pentatope numbers upto Nth term
- Find the Nth term of the series where each term f[i] = f[i - 1] - f[i - 2]
- Sum of series till N-th term whose i-th term is i^k - (i-1)^k
- as_integer_ratio() in Python for reduced fraction of a given rational
- Maximum rational number (or fraction) from an array
- n-th term of series 1, 17, 98, 354......
- N-th term in the series 1, 11, 55, 239, 991,....
- n-th term in series 2, 12, 36, 80, 150....
- Sum of first n term of Series 3, 5, 9, 17, 33....
- Program to print the sum of the given nth term
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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