An number x is call a beautiful number if: -D(x) = 1 or -x % D(x) = 0 (and x / D(x) also need to be beautiful) *D(x) is the length of x (if x = 123 => length x = 3) Write a python code to count beautiful number in a range(l,r) Cursed: (1 <= l <= r <= 10^18). run in less than 4s Example: l = 5; r = 15: 8 beautiful numbers: 5,6,7,8,9,10,12,14 5 is 1 digit .... 10 % D(x) = 0 I tried this but it's too slow python def check_BN(x): d = len(str(x)) if d == 1 or x % d == 0: return True return False def beautifulNumbers(l,r): count = 0 for i in range(l,r+1): if check_BN(i) and check_BN(i//len(str(i))): count += 1 return count Continue reading...