题目:
代码:
#!/bin/python3
import math
import os
import random
import re
import sys
def beautify(num, k):
return abs(int(str(num)) - int(str(num)[::-1])) % k == 0
# Complete the beautifulDays function below.
def beautifulDays(i, j, k):
cnt = 0
for m in range(i, j + 1):
if beautify(m, k):
cnt += 1
return cnt
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()
另外一个方法:
#!/bin/python3
import math
import os
import random
import re
import sys
# Complete the beautifulDays function below.
def beautifulDays(i, j, k):
number_list = []
for num in range(i,j+1):
number_list.append(num)
copy_from_origin_list = number_list.copy()
reverse_num = []
for m in range(len(number_list)):
new_num = 0
while(number_list[m] > 0):
remainder = number_list[m] % 10
new_num = (new_num * 10) + remainder
number_list[m] = number_list[m] // 10
reverse_num.append(new_num)
count = 0
for m in range(len(copy_from_origin_list)):
if abs(copy_from_origin_list[m] - reverse_num[m]) % k == 0:
count += 1
return count
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()
如果觉得不错,就点赞关注留言~
谢谢各位捧场~