The megastore offers a deal that states any product whose price is a golden price O would be given to them for free. A number G is said to have a guiden price if the difference betwe the highest digit and the sum of its digits equals the highest digit
Examples include 352 ((3+5+2)-5=5), 3003, and 32812 ((3+2+8+1+2)-8=8).
Narendra visits the megastore and purchases (Y, X+1) products with each of them in the price range of (X,Y) (X and Y are included in the product lot) and one product from each price value. He wants to know how much money he would have saved by picking products with the golden price.
Considering that you are a friend of Narendra, help Narendra with a program to figure out how much money he saved overall by buying Y-X+1 products between X and Y price range and every product price is different
Read the input from STDIN and write the output to STDOUT. You should not write arbitrary strings while reading the input and while printing as these contribute to the standard output
Input1
10 00
Output1
495
Input2
11 33
Output 2
66
Answers & Comments
Answer:
Explanation:
To solve this problem, you can iterate through the range of X to Y and check if each number in the range has a golden price. If it does, you can add the value of that number to a total savings variable. At the end, you can print the total savings.
Here is some sample code in Python that demonstrates this approach:
# Read the input values X and Y from stdin
x, y = map(int, input().split())
# Initialize the total savings to 0
total_savings = 0
# Iterate through the range of X to Y
for num in range(x, y+1):
# Convert the number to a string so we can access its digits
num_str = str(num)
# Find the highest digit in the number
highest_digit = max([int(d) for d in num_str])
# Find the sum of the digits in the number
digit_sum = sum([int(d) for d in num_str])
# Check if the difference between the highest digit and the sum of the digits is equal to the highest digit
if highest_digit == (digit_sum - highest_digit):
# If the number has a golden price, add its value to the total savings
total_savings += num
# Print the total savings
print(total_savings)
I hope this helps! Let me know if you have any questions.
Answer:
Please mark my answer as brainliest