We have a fraction in which if we cancel the common digit from the numerator and denominator, the fraction thus obtained is an equivalent fraction. This type of fraction is called a curious fraction.
There are indeed only four curious fractions whose actual value is less than one, with two digits in the numerator and denominator.
ex . 49/98 = 4/8
Suppose the following:
p/q = original fraction
i = digit to be cancelled
n/d = remaining fraction
After analyzing, we conclude that:
Out of four possible conditions, only the fourth condition will be true for a curious fraction less than one.
i > d > n
def gcd(a,b):b, a= min((a, b)), max((a, b))if a%b == 0: return b# if any of a or b is odd, then we will skip all odd factorsany_odd = (a|b)%2hcf = 1for j in range(2 + any_odd, b//2 + 1, 1 + any_odd):print('checking',j)if b%j == 0 and a%j == 0:hcf = jreturn hcf# num/den is the multiplication of all curious fraction less than 1num = 1den = 1# i is digit to be cancelledfor i in range(1, 10):# d is remaining digit in denominatorfor d in range(1, i):# n is remaining digit in numeratorfor n in range(1, d):if 10*n*d + i*d == 10*i*n + d*n:num *= 10*n + iden *= 10*i + dcommon_term = gcd(num, den)print(den//common_term)