HackerRank-Beautiful Days at the Movies


I just solved this problem in python,so that i want to share with you.

Problem:

Lily likes to play games with integers and their reversals. For some integer , we define to be the reversal of all digits in . For example, , , and .
Logan wants to go to the movies with Lily on some day satisfying , but he knows she only goes to the movies on days she considers to be beautiful. Lily considers a day to be beautiful if the absolute value of the difference between and is evenly divisible by .
Given , , and , count and print the number of beautiful days when Logan and Lily can go to the movies.

Input Format
A single line of three space-separated integers describing the respective values of , , and .
Constraints


Output Format
Print the number of beautiful days in the inclusive range between and .
Sample Input
20 23 6
 
Sample Output
2
 
Explanation
Logan wants to go to the movies on days , , , and . We perform the following calculations to determine which days are beautiful:
  • Day is beautiful because the following evaluates to a whole number:
  • Day is not beautiful because the following doesn't evaluate to a whole number:
  • Day is beautiful because the following evaluates to a whole number:
  • Day is not beautiful because the following doesn't evaluate to a whole number:
Only two days, and , in this interval are beautiful. Thus, we print as our answer.


Solution in Python 3:

i,j,k = map(int,input().split())#get i,j,k value in single linecount=0f=0def rev(e): return e[::-1] #reverse the string
for i in range(i,j+1):
    e = str(i) #convert to string
    d = rev(e) #call the function
    int(f)

    f= (int(i)-int(d))%int(k)#logic
    if(f==0):

        count = count+1
print(count)
  

Output

"C:\Program Files\Miniconda3\python.exe" C:/Users/Admin/PycharmProjects/crop/pra.py
20 23 62 
2
Process finished with exit code 0

Comments

Popular posts from this blog

Artificial Intelligence

The taxonomy of CASE Tools

Zoho Second round - adding a digit to all the digits of a number