查找两位数python结果的程序
编写一个程序,查找两个数字 A 和 B(不要在网上搜索, 并且不要尝试“手动”),以便我们得到一个两位数的数字 AB(例如 A = 8, B = 9 则数字为 89),因此 AB*AB = CAB 某个数字 C。因此,如果对 AB 进行平方,您将得到一个 3 位数字。这 AB^2 中的最后两位数字是 AB,但第一个数字是某个 C,可能 与 A 或 B 没有必然关系。
Write a program that finds two digit A and B (dont search the web,
and dont try 'manually') so that we get a two digit number AB (say
A = 8, B = 9 then the number is 89) and so that AB*AB = CAB for
some digit C. Thus if you square AB you get a 3 digit number. The
two last digits in AB^2 are AB but the first digit is some C that may
not related necessarily to A or B.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在伪代码中,您可以简单地执行以下操作:
我首选的伪代码语言与 Python 足够接近,因此转换起来应该不会太难,但您的第一步应该是了解它是如何转换的作品。为此,你应该在头脑中运行代码,填写一个变量表,例如:
你越早开始像机器一样思考,你就会成为更好的程序员 - 只要确保你不会启动所有这些社交技能不过,它们在您生活中的某些时刻仍然会派上用场:-)
In pseudo-code, you could simply do something like:
My preferred language for pseudo-code is close enough to Python that it shouldn't be too hard to convert but your first step should be understanding how it works. To that end you should run the code in your head, filling out a variable sheet like:
The sooner you start thinking like a machine, the better a programmer you'll become - just make sure you don't boot out all those social skills though, they'll still come in handy at certain points in your life :-)
简单来说,在代码中:
Simply, in code:
作为暴力破解的替代方案,请花两分钟思考一下问题。想想 A - A 的最小数字是多少?最大的是什么?想想 B - B 有一些特殊的东西,一些特殊的属性,总共 10 个数字中只有 4 个具有。最后,您仍然需要循环遍历 A 和 B 的几组数字,但如果您仅使用可能的数字集,您将表明您已经在解决方案中投入了一些聪明的想法。正如我之前所说,这个问题可以推广到一些有趣的较大情况,例如,您可以找到一个数字 ABCDEF,其平方得到 ######ABCDEF。
额外奖励:你认为拥有这个属性的可能数量最多吗?
As an alternative to brute force, take two minutes and think about the problem. Think about A - what is the smallest number A could be? What is the largest? Think about B - there is something special about B, some special property that only 4 of the total 10 digits have. In the end, you will still have to loop over a couple of sets of numbers for A and B, but if you use only the set of likely numbers, you will show that you have put some intelligent thought into your solution. And as I said before, this problem generalizes to some interesting larger cases, for instance, you can find a number ABCDEF which, when squared gives ######ABCDEF.
Bonus: do you think there is a largest possible number that has this property?