只需要考虑n的平方是否以n结尾即可,注意需要转换成字符串才能进行操作,代码如下:
while True: try: n = int(input()) m = 0 for i in range(n+1): if str(i ** 2).endswith(str(i)): m += 1 print(m) except: break
while True: try: n = int(input()) m = 0 for i in range(n+1): if str(i ** 2).endswith(str(i)): m += 1 print(m) except: break