Given two numbers X and Y, the task is to find the probability that an arbitrary positive divisor of 10X is an integral multiple of 10Y.
Note: Y should be <= X.
Input: X = 2, Y = 1
Positive divisors of 102 are 1, 2, 4, 5, 10, 20, 25, 50, 100. A total of 9.
Multiples of 101 upto 102 are 10, 20, 50, 100. A total of 4.
P(divisor of 102 is a multiple of 101) = 4/9.
Input: X = 99, Y = 88
A = 1099, B = 1088
P(divisor of 1099 is a multiple of 1088) = 9/625
Pre-requisites: Total number of divisors of a number
In order to solve the problem, we need to observe the steps below:
- All divisors of 10X will be of the form:
(2 P * 5 Q), where 0 <= P, Q <= X
- Find the number of Prime factors of 10X
10X = 2X * 5X
- Hence total number of divisors of 10X will be: ( X + 1 ) * ( X + 1 ).
- Now, consider all multiples of 10Y which can be potential divisors of 10X. They are also of the form:
( 2 A * 5 B ), where Y <= A, B <= X.
- So, count of potential divisors of 10X which are also multiples of 10Y is ( X – Y + 1 ) * ( X – Y + 1 ).
- Hence, required probability is (( X – Y + 1 ) * ( X – Y + 1 )) / (( X + 1 ) * ( X + 1 )). Computing the value of the expression for given values of X and Y gives us the required probability.
Below is the implementation of the above approach:
Time Complexity: O(log(N))