We are given two numbers A and B. We need to calculate the number of digits after decimal. If in case the numbers are irrational then print “INF”.
Input : x = 5, y = 3 Output : INF 5/3 = 1.666.... Input : x = 3, y = 6 Output : 1 3/6 = 0.5
The idea is simple we follow school division and keep track of remainders while dividing one by one. If remainder becomes 0, we return count of digits seen after decimal. If remainder repeats, we return INF.
1 INF 1
This article is contributed by Rahul Chawla. 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 write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
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.
- Count subarrays such that remainder after dividing sum of elements by K gives count of elements
- Maximum sum after repeatedly dividing N by a divisor
- Convert Decimal To Hexa-Decimal including negative numbers
- Count of divisors having more set bits than quotient on dividing N
- Numbers of Length N having digits A and B and whose sum of digits contain only digits A and B
- Minimum digits to be removed to make either all digits or alternating digits same
- Largest number dividing maximum number of elements in the array
- Smallest number dividing minimum number of elements in the array | Set 2
- Smallest number dividing minimum number of elements in the Array
- Given a number N in decimal base, find number of its digits in any base (base b)
- Smallest number to make Array sum at most K by dividing each element
- Number of digits before the decimal point in the division of two numbers
- Given a number N in decimal base, find the sum of digits in any base B
- Maximum value with the choice of either dividing or considering as it is
- Ways of dividing a group into two halves such that two elements are in different groups
- Minimum integer such that it leaves a remainder 1 on dividing with any element from the range [2, N]
- Minimize sum by dividing all elements of a subarray by K
- Puzzle | Dividing a Square into N smaller squares
- Min operations to reduce N to 1 by multiplying by A or dividing by B
- Count of integers in a range which have even number of odd digits and odd number of even digits