什么时候n匹配n ^ 2的最后一位? [英] When does `n` match last digits of `n^2`?

查看:67
本文介绍了什么时候n匹配n ^ 2的最后一位?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在解决一个编程问题.

I'm solving one programming problem.

查找从1n的所有数字x,这些数字具有数字的属性 x^2末尾的x个匹配数字.

Find all numbers x from 1 to n that have a property that digits of x match digits at the end of x^2.

例如:

5 matches last digit of 5^2 (25)
6 matches last digit of 6^2 (36)
25 matches last digits of 25^2 (625)
76 matches last digits of 76^2 (5776)
376 matches last digits of 376^2 (141376)
625 matches last digits of 625^2 (390625)
etc.

有人知道数字与数字的最后几位相匹配的数字标准是什么吗?

Does anyone know what the numerical criteria is for a number to match itself in last digits of it squared?

我正在用Python进行编程,我只能使用数字运算,例如/%//*+等.

I'm programming this in Python and I can only use numeric operations such as /, %, //, *, +, etc.

我不能使用strlen或字符串函数对数字进行切片.

I can't use str or len or string functions to slice numbers.

推荐答案

我写了这个答案:

n=int(input('n='))

for m in range(1, n+1):
    d=m**2
    x = m

    all = 0
    all2 = 0

    while x != 0:
        if x%10 == d%10:
            all += 1
        x = x//10
        d = d//10
        all2 += 1

    if all == all2:
        print m

请让我知道您的想法-可以!

Please let me know what you think -- it works!

这篇关于什么时候n匹配n ^ 2的最后一位?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆