题解 | #自守数#

自守数

http://www.nowcoder.com/practice/88ddd31618f04514ae3a689e83f3ab8e

import sys
check_str = "0156" #位数为0,1,5,6才可能是自守数
def calc_automorphic_numbers(n):
    count = 0
    for i in range(n+1):
        i_s = str(i%10)
        if i_s not in check_str:
            continue

        #先平方然后转成字符串,再判断是否以i结尾
        if str(i**2).endswith(str(i)):
            count += 1
    return count

while True:
    try:
        n = int(input())
        print(calc_automorphic_numbers(n))
    except:
#         print(sys.exc_info())
        break












全部评论

相关推荐

陆续:不可思议 竟然没那就话 那就我来吧 :你是我在牛客见到的最美的女孩
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务