-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbeautiful-days-at-the-movies.py
68 lines (51 loc) · 1.9 KB
/
beautiful-days-at-the-movies.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
'''
Problem
Lily likes to play games with integers. She has created a new game where she determines the difference between a number and its reverse. For instance, given the number , its reverse is . Their difference is . The number reversed is , and their difference is .
She decides to apply her game to decision making. She will look at a numbered range of days and will only go to a movie on a beautiful day.
Given a range of numbered days, and a number , determine the number of days in the range that are beautiful. Beautiful numbers are defined as numbers where is evenly divisible by . If a day's value is a beautiful number, it is a beautiful day. Print the number of beautiful days in the range.
Function Description
Complete the beautifulDays function in the editor below. It must return the number of beautiful days in the range.
beautifulDays has the following parameter(s):
i: the starting day number
j: the ending day number
k: the divisor
Input Format
A single line of three space-separated integers describing the respective values of , , and .
Constraints
1<i<=j<=2*10**6
1<=k<=2*10**9
Output Format
Print the number of beautiful days in the inclusive range between and .
'''
#!/bin/python3
import math
import os
import random
import re
import sys
# Complete the beautifulDays function below.
def beautifulDays(i, j, k):
count = 0
for num in range(i,j+1):
rev=reverseDigits(num)
print((abs(num-rev)))
if (abs(num-rev)%k)== 0:
count+=1
return count
#reverses the Digits
def reverseDigits(num):
rev = 0
while(num > 0):
a = num % 10
rev = rev * 10 + a
num = num // 10
return rev
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
ijk = input().split()
i = int(ijk[0])
j = int(ijk[1])
k = int(ijk[2])
result = beautifulDays(i, j, k)
fptr.write(str(result) + '\n')
fptr.close()