Probability that an arbitrary positive divisor of 10^X is an integral multiple of 10^Y

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.
Examples:

Input: X = 2, Y = 1
Output: 4/9
Explanation:
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
Output: 9/625
Explanation:
A = 1099, B = 1088
P(divisor of 1099 is a multiple of 1088) = 9/625

Pre-requisites: Total number of divisors of a number



Approach:
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:

C++

filter_none

edit
close

play_arrow

link
brightness_4
code

// C++ program to find the probability
// of an arbitrary positive divisor of
// Xth power of 10 to be a multiple of
// Yth power of 10
  
#include <bits/stdc++.h>
using namespace std;
#define int long long int
  
// Function to calculate and print
// the required probability
void prob(int x, int y)
{
    // Count of potential divisors
    // of X-th power of 10 which are
    // also multiples of Y-th power
    // of 10
    int num = abs(x - y + 1)
              * abs(x - y + 1);
  
    // Count of divisors of X-th
    // power of 10
    int den = (x + 1) * (x + 1);
  
    // Calculate GCD
    int gcd = __gcd(num, den);
  
    // Print the reduced
    // fraction probability
    cout << num / gcd << "/"
         << den / gcd << endl;
}
  
// Driver Code
signed main()
{
    int X = 2, Y = 1;
    prob(X, Y);
    return 0;
}

chevron_right


Java

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java program to find the probability
// of an arbitrary positive divisor of
// Xth power of 10 to be a multiple of
// Yth power of 10
import java.util.*;
  
class GFG{
  
// Function to calculate and print
// the required probability
static void prob(int x, int y)
{
      
    // Count of potential divisors
    // of X-th power of 10 which are
    // also multiples of Y-th power
    // of 10
    int num = Math.abs(x - y + 1) * 
              Math.abs(x - y + 1);
  
    // Count of divisors of X-th
    // power of 10
    int den = (x + 1) * (x + 1);
  
    // Calculate GCD
    int gcd = __gcd(num, den);
  
    // Print the reduced
    // fraction probability
    System.out.print(num / gcd + "/"
                     den / gcd + "\n");
}
  
static int __gcd(int a, int b) 
    return b == 0 ? a : __gcd(b, a % b);     
  
// Driver code
public static void main(String[] args)
{
    int X = 2, Y = 1;
      
    prob(X, Y);
}
}
  
// This code is contributed by amal kumar choubey

chevron_right


Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python3 program to find the probability
# of an arbitrary positive divisor of
# Xth power of 10 to be a multiple of
# Yth power of 10
from math import *
  
# Function to calculate and print
# the required probability
def prob(x, y):
      
    # Count of potential divisors
    # of X-th power of 10 which are
    # also multiples of Y-th power
    # of 10
    num = abs(x - y + 1) * abs(x - y + 1)
  
    # Count of divisors of X-th
    # power of 10
    den = (x + 1) * (x + 1)
  
    # Calculate GCD
    gcd1 = gcd(num, den)
  
    # Print the reduced
    # fraction probability
    print(num // gcd1, end = "")
    print("/", end = "")
    print(den // gcd1)
  
# Driver Code
if __name__ == '__main__':
      
    X = 2
    Y = 1
      
    prob(X, Y)
      
# This code is contributed by Surendra_Gangwar

chevron_right


C#

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program to find the probability 
// of an arbitrary positive divisor of 
// Xth power of 10 to be a multiple of 
// Yth power of 10 
using System;
class GFG{ 
  
// Function to calculate and print 
// the required probability 
static void prob(int x, int y) 
      
    // Count of potential divisors 
    // of X-th power of 10 which are 
    // also multiples of Y-th power 
    // of 10 
    int num = Math.Abs(x - y + 1) * 
              Math.Abs(x - y + 1); 
  
    // Count of divisors of X-th 
    // power of 10 
    int den = (x + 1) * (x + 1); 
  
    // Calculate GCD 
    int gcd = __gcd(num, den); 
  
    // Print the reduced 
    // fraction probability 
    Console.Write(num / gcd + "/"
                  den / gcd + "\n"); 
  
static int __gcd(int a, int b) 
    return b == 0 ? a : __gcd(b, a % b);     
  
// Driver code 
public static void Main(string[] args) 
    int X = 2, Y = 1; 
      
    prob(X, Y); 
  
// This code is contributed by AnkitRai01 

chevron_right


Output:

4/9

Time Complexity: O(log(N))

competitive-programming-img




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.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.